@ledgerhq/device-signer-kit-ethereum 1.9.4 → 1.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.test.js +1 -1
- package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/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/package.json +3 -3
- package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js.map +2 -2
- package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.test.js +1 -1
- package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.test.js.map +2 -2
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
- package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +3 -3
- package/lib/esm/package.json +3 -3
- package/lib/types/internal/app-binder/task/BuildSubcontextsTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +8 -8
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/task/BuildSubcontextsTask.test.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type ClearSignContextReference,\n ClearSignContextReferenceType,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type GenericPath,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nimport {\n BuildSubcontextsTask,\n type BuildSubcontextsTaskArgs,\n} from \"./BuildSubcontextsTask\";\n\ndescribe(\"BuildSubcontextsTask\", () => {\n const contextModuleMock = {\n getFieldContext: vi.fn(),\n };\n const transactionParserMock = {\n extractValue: vi.fn(),\n };\n const apiMock = makeDeviceActionInternalApiMock();\n\n let defaultArgs: BuildSubcontextsTaskArgs;\n\n beforeEach(() => {\n vi.resetAllMocks();\n defaultArgs = {\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"test payload\",\n },\n contextOptional: [],\n transactionParser:\n transactionParserMock as unknown as TransactionParserService,\n subset: {\n chainId: 1,\n data: \"0x\",\n selector: \"0x\",\n to: \"0x\",\n value: BigInt(0),\n },\n contextModule: contextModuleMock as unknown as ContextModule,\n deviceModelId: DeviceModelId.STAX,\n };\n });\n\n describe(\"when context type is a simple type\", () => {\n const simpleTypes: ClearSignContextSuccess[\"type\"][] = [\n ClearSignContextType.TRANSACTION_INFO,\n ClearSignContextType.TRANSACTION_CHECK,\n ClearSignContextType.PLUGIN,\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ClearSignContextType.ENUM,\n ClearSignContextType.TRUSTED_NAME,\n ClearSignContextType.TOKEN,\n ClearSignContextType.NFT,\n ];\n\n it.each(simpleTypes)(\n \"should return context with empty subcontextCallbacks for %s\",\n (type) => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type,\n payload: \"test payload\",\n } as ClearSignContextSuccess;\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n },\n );\n });\n\n describe(\"when context has a direct value reference\", () => {\n it(\"should create a callback to get context with the direct value\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TOKEN,\n value: \"0x1234567890123456789012345678901234567890\",\n },\n };\n const args = { ...defaultArgs, context };\n const expectedContext = {\n chainId: 1,\n address: \"0x1234567890123456789012345678901234567890\",\n };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n\n // Verify the callback calls getContext with correct parameters\n const callback = result.subcontextCallbacks[0]!;\n await callback();\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n expectedContext,\n ClearSignContextType.TOKEN,\n );\n });\n\n it(\"should handle undefined value in reference\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: undefined as unknown as ClearSignContextReference,\n };\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"when context has a valuePath reference\", () => {\n beforeEach(() => {\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: \"test-challenge\" } }),\n );\n });\n\n describe(\"when extractValue returns Left (error)\", () => {\n it(\"should return context with empty subcontextCallbacks\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: [{ type: \"SLICE\", start: 0, end: 20 }],\n },\n };\n const args = { ...defaultArgs, context };\n transactionParserMock.extractValue.mockReturnValue(\n Left(new Error(\"Extraction failed\")),\n );\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"when extractValue returns Right with values\", () => {\n describe(\"for ENUM type\", () => {\n it(\"should create callbacks for matching enum contexts\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.ENUM,\n id: 1,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n // enum with the same id but different value\n const enumContext1: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 1,\n value: 1,\n payload: \"enum context 1\",\n };\n // enum to select, id and value match\n const enumContext2: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 1,\n value: 2,\n payload: \"enum context 2\",\n };\n // other enum context with different id\n const enumContext3: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 2,\n value: 2,\n payload: \"enum context 3\",\n };\n const args = {\n ...defaultArgs,\n context,\n contextOptional: [enumContext1, enumContext2, enumContext3],\n };\n const extractedValues = [new Uint8Array([0x01, 0x02])]; // Last byte is 2\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual(enumContext2);\n });\n\n it(\"should create callbacks for matching enum contexts with two values\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.ENUM,\n id: 1,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n // enum to select, id and value match\n const enumContext1: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 1,\n value: 1,\n payload: \"enum context 1\",\n };\n // enum to select, id and value match\n const enumContext2: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 1,\n value: 2,\n payload: \"enum context 2\",\n };\n // other enum context with different id\n const enumContext3: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 2,\n value: 2,\n payload: \"enum context 3\",\n };\n const args = {\n ...defaultArgs,\n context,\n contextOptional: [enumContext1, enumContext2, enumContext3],\n };\n const extractedValues = [\n new Uint8Array([0x01, 0x02]),\n new Uint8Array([0x03, 0x02, 0x01]),\n ]; // Last byte is 2\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(2);\n const callback1 = result.subcontextCallbacks[0]!;\n const callback2 = result.subcontextCallbacks[1]!;\n const callbackResult1 = await callback1();\n const callbackResult2 = await callback2();\n expect(callbackResult1).toEqual(enumContext2);\n expect(callbackResult2).toEqual(enumContext1);\n });\n\n it(\"should skip when enum value is undefined\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.ENUM,\n id: 1,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [new Uint8Array([])]; // Empty array\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n\n it(\"should create callback with enum id 0\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.ENUM,\n id: 0,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const enumContext1: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 0,\n value: 0,\n payload: \"enum context 1\",\n };\n const enumContext2: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 1,\n value: 1,\n payload: \"enum context 2\",\n };\n const args = {\n ...defaultArgs,\n context,\n contextOptional: [enumContext1, enumContext2],\n };\n const extractedValues = [new Uint8Array([0x01, 0x00])];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual(enumContext1);\n });\n\n it(\"should skip when no matching enum context found\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.ENUM,\n id: 1,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const enumContext: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 2, // Different ID\n value: 2,\n payload: \"enum context\",\n };\n const args = {\n ...defaultArgs,\n context,\n contextOptional: [enumContext],\n };\n const extractedValues = [new Uint8Array([0x01, 0x02])];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"for TOKEN type\", () => {\n it(\"should create callbacks to get token context\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [\n new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,\n ]),\n ];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.TOKEN,\n payload: \"token result\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"token result\",\n });\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n address: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n },\n ClearSignContextType.TOKEN,\n );\n });\n\n it(\"should create callbacks to get token as constant\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TOKEN,\n value: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n },\n };\n const args = { ...defaultArgs, context };\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.TOKEN,\n payload: \"token result\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"token result\",\n });\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n address: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n },\n ClearSignContextType.TOKEN,\n );\n });\n });\n\n describe(\"for NFT type\", () => {\n it(\"should create callbacks to get NFT context\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.NFT,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [\n new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,\n ]),\n ];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.NFT,\n payload: \"nft result\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.NFT,\n payload: \"nft result\",\n });\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n address: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n },\n ClearSignContextType.NFT,\n );\n });\n\n it(\"should create callbacks to get NFT as constant\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.NFT,\n value: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n },\n };\n const args = { ...defaultArgs, context };\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.NFT,\n payload: \"nft result\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.NFT,\n payload: \"nft result\",\n });\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n address: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n },\n ClearSignContextType.NFT,\n );\n });\n });\n\n describe(\"for TRUSTED_NAME type\", () => {\n it(\"should create callbacks to get trusted name context with challenge\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TRUSTED_NAME,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n types: [\"type1\", \"type2\"],\n sources: [\"source1\", \"source2\"],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [\n new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,\n ]),\n ];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: \"trusted name result\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: \"trusted name result\",\n });\n expect(apiMock.sendCommand).toHaveBeenCalledWith(\n expect.any(GetChallengeCommand),\n );\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n address: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n challenge: \"test-challenge\",\n types: [\"type1\", \"type2\"],\n sources: [\"source1\", \"source2\"],\n deviceModelId: DeviceModelId.STAX,\n },\n ClearSignContextType.TRUSTED_NAME,\n );\n });\n\n it(\"should handle challenge command failure\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TRUSTED_NAME,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n types: [\"type1\"],\n sources: [\"source1\"],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [\n new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,\n ]),\n ];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n const error = new UnknownDeviceExchangeError(\"Failed\");\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n error,\n }),\n );\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n error: new Error(\"Failed to get challenge\"),\n type: ClearSignContextType.ERROR,\n });\n });\n });\n\n describe(\"for multiple values\", () => {\n it(\"should create callbacks for each extracted value\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [\n new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,\n ]),\n new Uint8Array([\n 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,\n 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,\n ]),\n ];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getFieldContext.mockResolvedValueOnce({\n type: ClearSignContextType.TOKEN,\n payload: \"token result 1\",\n });\n contextModuleMock.getFieldContext.mockResolvedValueOnce({\n type: ClearSignContextType.TOKEN,\n payload: \"token result 2\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(2);\n const callback1 = result.subcontextCallbacks[0]!;\n const callback2 = result.subcontextCallbacks[1]!;\n const callbackResult1 = await callback1();\n const callbackResult2 = await callback2();\n expect(callbackResult1).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"token result 1\",\n });\n expect(callbackResult2).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"token result 2\",\n });\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledTimes(2);\n expect(contextModuleMock.getFieldContext).toHaveBeenNthCalledWith(\n 1,\n {\n chainId: 1,\n address: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n },\n ClearSignContextType.TOKEN,\n );\n expect(contextModuleMock.getFieldContext).toHaveBeenNthCalledWith(\n 2,\n {\n chainId: 1,\n address: \"0x232425262728292a2b2c2d2e2f30313233343536\",\n },\n ClearSignContextType.TOKEN,\n );\n });\n });\n });\n });\n\n describe(\"when context has no reference\", () => {\n it(\"should return context with empty subcontextCallbacks\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TOKEN,\n payload: \"test payload\",\n };\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"when context has reference but no valuePath\", () => {\n it(\"should return context with empty subcontextCallbacks\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: undefined as unknown as GenericPath,\n },\n };\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"error handling\", () => {\n it(\"should throw error for uncovered context type\", () => {\n // GIVEN\n const context = {\n type: \"UNKNOWN_TYPE\" as ClearSignContextSuccess[\"type\"],\n payload: \"test payload\",\n } as ClearSignContextSuccess;\n const args = { ...defaultArgs, context };\n\n // WHEN / THEN\n expect(() => new BuildSubcontextsTask(apiMock, args).run()).toThrow(\n \"Uncovered type: UNKNOWN_TYPE\",\n );\n });\n\n it(\"should throw error for uncovered reference type\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: \"UNKNOWN_REFERENCE_TYPE\" as ClearSignContextReference[\"type\"],\n } as ClearSignContextReference,\n };\n const args = { ...defaultArgs, context };\n\n // WHEN / THEN\n expect(() => new BuildSubcontextsTask(apiMock, args).run()).toThrow(\n \"Uncovered reference type: UNKNOWN_REFERENCE_TYPE\",\n );\n });\n });\n\n describe(\"CALLDATA reference type\", () => {\n it(\"should return empty subcontextCallbacks for CALLDATA reference\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.CALLDATA,\n callee: [{ type: \"TUPLE\", offset: 0 }],\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"references without valuePath\", () => {\n it(\"should return empty subcontextCallbacks for ENUM reference without valuePath\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.ENUM,\n id: 1,\n valuePath: undefined as unknown as GenericPath,\n },\n };\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n\n it(\"should return empty subcontextCallbacks for TRUSTED_NAME reference without valuePath\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TRUSTED_NAME,\n types: [\"type1\"],\n sources: [\"source1\"],\n valuePath: undefined as unknown as GenericPath,\n },\n };\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"PROXY_INFO context type\", () => {\n beforeEach(() => {\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: \"test-challenge\" } }),\n );\n });\n\n it(\"should create callback to get proxy delegate call context\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"proxy payload\",\n };\n const args = {\n ...defaultArgs,\n context,\n subset: {\n ...defaultArgs.subset,\n to: \"0x1234567890123456789012345678901234567890\",\n data: \"0xabcdef\",\n },\n };\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.PROXY_INFO,\n payload: \"proxy result\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n\n expect(callbackResult).toEqual({\n type: ClearSignContextType.PROXY_INFO,\n payload: \"proxy result\",\n });\n expect(apiMock.sendCommand).toHaveBeenCalledWith(\n expect.any(GetChallengeCommand),\n );\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n proxyAddress: \"0x1234567890123456789012345678901234567890\",\n calldata: \"0xabcdef\",\n deviceModelId: DeviceModelId.STAX,\n challenge: \"test-challenge\",\n },\n ClearSignContextType.PROXY_INFO,\n );\n });\n\n it(\"should handle challenge command failure\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"proxy payload\",\n };\n const args = {\n ...defaultArgs,\n context,\n subset: {\n ...defaultArgs.subset,\n to: \"0x1234567890123456789012345678901234567890\",\n data: \"0xabcdef\",\n },\n };\n const error = new UnknownDeviceExchangeError(\"Failed\");\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n error,\n }),\n );\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n\n expect(callbackResult).toEqual({\n error: new Error(\"Failed to get challenge\"),\n type: ClearSignContextType.ERROR,\n });\n expect(apiMock.sendCommand).toHaveBeenCalledWith(\n expect.any(GetChallengeCommand),\n );\n expect(contextModuleMock.getFieldContext).not.toHaveBeenCalled();\n });\n\n it(\"should handle missing proxy address\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"proxy payload\",\n };\n const args = {\n ...defaultArgs,\n context,\n subset: {\n ...defaultArgs.subset,\n to: undefined,\n data: \"0xabcdef\",\n },\n };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n\n expect(callbackResult).toEqual({\n error: new Error(\"Failed to get proxy address\"),\n type: ClearSignContextType.ERROR,\n });\n expect(apiMock.sendCommand).toHaveBeenCalledWith(\n expect.any(GetChallengeCommand),\n );\n expect(contextModuleMock.getFieldContext).not.toHaveBeenCalled();\n });\n\n it(\"should use correct device model id in context\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"proxy payload\",\n };\n const args = {\n ...defaultArgs,\n context,\n deviceModelId: DeviceModelId.NANO_SP,\n subset: {\n ...defaultArgs.subset,\n to: \"0x1234567890123456789012345678901234567890\",\n data: \"0xabcdef\",\n },\n };\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.PROXY_INFO,\n payload: \"proxy result\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n await callback();\n\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n proxyAddress: \"0x1234567890123456789012345678901234567890\",\n calldata: \"0xabcdef\",\n deviceModelId: DeviceModelId.NANO_SP,\n challenge: \"test-challenge\",\n },\n ClearSignContextType.PROXY_INFO,\n );\n });\n });\n\n describe(\"edge cases\", () => {\n it(\"should handle value array shorter than 20 bytes for address extraction\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [new Uint8Array([0x01, 0x02, 0x03])]; // Only 3 bytes\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.ERROR,\n message: \"Invalid address\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.ERROR,\n message: \"Invalid address\",\n });\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n address: \"0x010203\",\n },\n ClearSignContextType.TOKEN,\n );\n });\n\n it(\"should handle empty value array\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [new Uint8Array([])]; // Empty array\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.TOKEN,\n payload: \"token result\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n\n // Verify the callback calls getContext with empty address\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"token result\",\n });\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n address: \"0x\",\n },\n ClearSignContextType.TOKEN,\n );\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "AAAA,OAEE,iCAAAA,EAEA,wBAAAC,MAGK,2BACP,OACE,wBAAAC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C,SAAY,CAEhD,MAAMiB,EAAmC,CACvC,KAAMjB,EAAqB,8BAC3B,QAAS,eACT,UAAW,CACT,KAAMD,EAA8B,MACpC,UAAW,CAAC,CAAE,KAAM,QAAS,OAAQ,CAAE,CAAC,CAC1C,CACF,EACMgB,EAAO,CAAE,GAAGH,EAAa,QAAAK,CAAQ,EACjCM,EAAkB,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,EAC3Cb,EAAsB,aAAa,gBACjCL,EAAMkB,CAAe,CACvB,EACAd,EAAkB,gBAAgB,kBAAkB,CAClD,KAAMT,EAAqB,MAC3B,QAAS,cACX,CAAC,EAGD,MAAMgB,EAAS,IAAIR,EAAqBG,EAASI,CAAI,EAAE,IAAI,EAG3D,OAAOC,EAAO,mBAAmB,EAAE,aAAa,CAAC,EAGjD,MAAMG,EAAWH,EAAO,oBAAoB,CAAC,EACvCQ,EAAiB,MAAML,EAAS,EACtC,OAAOK,CAAc,EAAE,QAAQ,CAC7B,KAAMxB,EAAqB,MAC3B,QAAS,cACX,CAAC,EACD,OAAOS,EAAkB,eAAe,EAAE,qBACxC,CACE,QAAS,EACT,QAAS,IACX,EACAT,EAAqB,KACvB,CACF,CAAC,CACH,CAAC,CACH,CAAC",
|
|
4
|
+
"sourcesContent": ["import {\n type ClearSignContextReference,\n ClearSignContextReferenceType,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type GenericPath,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceModelId,\n UnknownDeviceExchangeError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nimport {\n BuildSubcontextsTask,\n type BuildSubcontextsTaskArgs,\n} from \"./BuildSubcontextsTask\";\n\ndescribe(\"BuildSubcontextsTask\", () => {\n const contextModuleMock = {\n getFieldContext: vi.fn(),\n };\n const transactionParserMock = {\n extractValue: vi.fn(),\n };\n const apiMock = makeDeviceActionInternalApiMock();\n\n let defaultArgs: BuildSubcontextsTaskArgs;\n\n beforeEach(() => {\n vi.resetAllMocks();\n defaultArgs = {\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"test payload\",\n },\n contextOptional: [],\n transactionParser:\n transactionParserMock as unknown as TransactionParserService,\n subset: {\n chainId: 1,\n data: \"0x\",\n selector: \"0x\",\n to: \"0x\",\n value: BigInt(0),\n },\n contextModule: contextModuleMock as unknown as ContextModule,\n deviceModelId: DeviceModelId.STAX,\n };\n });\n\n describe(\"when context type is a simple type\", () => {\n const simpleTypes: ClearSignContextSuccess[\"type\"][] = [\n ClearSignContextType.TRANSACTION_INFO,\n ClearSignContextType.TRANSACTION_CHECK,\n ClearSignContextType.PLUGIN,\n ClearSignContextType.EXTERNAL_PLUGIN,\n ClearSignContextType.DYNAMIC_NETWORK,\n ClearSignContextType.DYNAMIC_NETWORK_ICON,\n ClearSignContextType.ENUM,\n ClearSignContextType.TRUSTED_NAME,\n ClearSignContextType.TOKEN,\n ClearSignContextType.NFT,\n ];\n\n it.each(simpleTypes)(\n \"should return context with empty subcontextCallbacks for %s\",\n (type) => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type,\n payload: \"test payload\",\n } as ClearSignContextSuccess;\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n },\n );\n });\n\n describe(\"when context has a direct value reference\", () => {\n it(\"should create a callback to get context with the direct value\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TOKEN,\n value: \"0x1234567890123456789012345678901234567890\",\n },\n };\n const args = { ...defaultArgs, context };\n const expectedContext = {\n chainId: 1,\n address: \"0x1234567890123456789012345678901234567890\",\n deviceModelId: DeviceModelId.STAX,\n };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n\n // Verify the callback calls getContext with correct parameters\n const callback = result.subcontextCallbacks[0]!;\n await callback();\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n expectedContext,\n ClearSignContextType.TOKEN,\n );\n });\n\n it(\"should handle undefined value in reference\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: undefined as unknown as ClearSignContextReference,\n };\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"when context has a valuePath reference\", () => {\n beforeEach(() => {\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: \"test-challenge\" } }),\n );\n });\n\n describe(\"when extractValue returns Left (error)\", () => {\n it(\"should return context with empty subcontextCallbacks\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: [{ type: \"SLICE\", start: 0, end: 20 }],\n },\n };\n const args = { ...defaultArgs, context };\n transactionParserMock.extractValue.mockReturnValue(\n Left(new Error(\"Extraction failed\")),\n );\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"when extractValue returns Right with values\", () => {\n describe(\"for ENUM type\", () => {\n it(\"should create callbacks for matching enum contexts\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.ENUM,\n id: 1,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n // enum with the same id but different value\n const enumContext1: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 1,\n value: 1,\n payload: \"enum context 1\",\n };\n // enum to select, id and value match\n const enumContext2: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 1,\n value: 2,\n payload: \"enum context 2\",\n };\n // other enum context with different id\n const enumContext3: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 2,\n value: 2,\n payload: \"enum context 3\",\n };\n const args = {\n ...defaultArgs,\n context,\n contextOptional: [enumContext1, enumContext2, enumContext3],\n };\n const extractedValues = [new Uint8Array([0x01, 0x02])]; // Last byte is 2\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual(enumContext2);\n });\n\n it(\"should create callbacks for matching enum contexts with two values\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.ENUM,\n id: 1,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n // enum to select, id and value match\n const enumContext1: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 1,\n value: 1,\n payload: \"enum context 1\",\n };\n // enum to select, id and value match\n const enumContext2: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 1,\n value: 2,\n payload: \"enum context 2\",\n };\n // other enum context with different id\n const enumContext3: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 2,\n value: 2,\n payload: \"enum context 3\",\n };\n const args = {\n ...defaultArgs,\n context,\n contextOptional: [enumContext1, enumContext2, enumContext3],\n };\n const extractedValues = [\n new Uint8Array([0x01, 0x02]),\n new Uint8Array([0x03, 0x02, 0x01]),\n ]; // Last byte is 2\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(2);\n const callback1 = result.subcontextCallbacks[0]!;\n const callback2 = result.subcontextCallbacks[1]!;\n const callbackResult1 = await callback1();\n const callbackResult2 = await callback2();\n expect(callbackResult1).toEqual(enumContext2);\n expect(callbackResult2).toEqual(enumContext1);\n });\n\n it(\"should skip when enum value is undefined\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.ENUM,\n id: 1,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [new Uint8Array([])]; // Empty array\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n\n it(\"should create callback with enum id 0\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.ENUM,\n id: 0,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const enumContext1: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 0,\n value: 0,\n payload: \"enum context 1\",\n };\n const enumContext2: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 1,\n value: 1,\n payload: \"enum context 2\",\n };\n const args = {\n ...defaultArgs,\n context,\n contextOptional: [enumContext1, enumContext2],\n };\n const extractedValues = [new Uint8Array([0x01, 0x00])];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual(enumContext1);\n });\n\n it(\"should skip when no matching enum context found\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.ENUM,\n id: 1,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const enumContext: ClearSignContextSuccess = {\n type: ClearSignContextType.ENUM,\n id: 2, // Different ID\n value: 2,\n payload: \"enum context\",\n };\n const args = {\n ...defaultArgs,\n context,\n contextOptional: [enumContext],\n };\n const extractedValues = [new Uint8Array([0x01, 0x02])];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"for TOKEN type\", () => {\n it(\"should create callbacks to get token context\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [\n new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,\n ]),\n ];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.TOKEN,\n payload: \"token result\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"token result\",\n });\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n address: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n deviceModelId: DeviceModelId.STAX,\n },\n ClearSignContextType.TOKEN,\n );\n });\n\n it(\"should create callbacks to get token as constant\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TOKEN,\n value: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n },\n };\n const args = { ...defaultArgs, context };\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.TOKEN,\n payload: \"token result\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"token result\",\n });\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n address: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n deviceModelId: DeviceModelId.STAX,\n },\n ClearSignContextType.TOKEN,\n );\n });\n });\n\n describe(\"for NFT type\", () => {\n it(\"should create callbacks to get NFT context\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.NFT,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [\n new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,\n ]),\n ];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.NFT,\n payload: \"nft result\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.NFT,\n payload: \"nft result\",\n });\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n address: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n deviceModelId: DeviceModelId.STAX,\n },\n ClearSignContextType.NFT,\n );\n });\n\n it(\"should create callbacks to get NFT as constant\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.NFT,\n value: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n },\n };\n const args = { ...defaultArgs, context };\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.NFT,\n payload: \"nft result\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.NFT,\n payload: \"nft result\",\n });\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n address: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n deviceModelId: DeviceModelId.STAX,\n },\n ClearSignContextType.NFT,\n );\n });\n });\n\n describe(\"for TRUSTED_NAME type\", () => {\n it(\"should create callbacks to get trusted name context with challenge\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TRUSTED_NAME,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n types: [\"type1\", \"type2\"],\n sources: [\"source1\", \"source2\"],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [\n new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,\n ]),\n ];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: \"trusted name result\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.TRUSTED_NAME,\n payload: \"trusted name result\",\n });\n expect(apiMock.sendCommand).toHaveBeenCalledWith(\n expect.any(GetChallengeCommand),\n );\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n address: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n challenge: \"test-challenge\",\n types: [\"type1\", \"type2\"],\n sources: [\"source1\", \"source2\"],\n deviceModelId: DeviceModelId.STAX,\n },\n ClearSignContextType.TRUSTED_NAME,\n );\n });\n\n it(\"should handle challenge command failure\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TRUSTED_NAME,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n types: [\"type1\"],\n sources: [\"source1\"],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [\n new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,\n ]),\n ];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n const error = new UnknownDeviceExchangeError(\"Failed\");\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n error,\n }),\n );\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n error: new Error(\"Failed to get challenge\"),\n type: ClearSignContextType.ERROR,\n });\n });\n });\n\n describe(\"for multiple values\", () => {\n it(\"should create callbacks for each extracted value\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [\n new Uint8Array([\n 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,\n 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,\n ]),\n new Uint8Array([\n 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,\n 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,\n ]),\n ];\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getFieldContext.mockResolvedValueOnce({\n type: ClearSignContextType.TOKEN,\n payload: \"token result 1\",\n });\n contextModuleMock.getFieldContext.mockResolvedValueOnce({\n type: ClearSignContextType.TOKEN,\n payload: \"token result 2\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(2);\n const callback1 = result.subcontextCallbacks[0]!;\n const callback2 = result.subcontextCallbacks[1]!;\n const callbackResult1 = await callback1();\n const callbackResult2 = await callback2();\n expect(callbackResult1).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"token result 1\",\n });\n expect(callbackResult2).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"token result 2\",\n });\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledTimes(2);\n expect(contextModuleMock.getFieldContext).toHaveBeenNthCalledWith(\n 1,\n {\n chainId: 1,\n address: \"0x030405060708090a0b0c0d0e0f10111213141516\",\n deviceModelId: DeviceModelId.STAX,\n },\n ClearSignContextType.TOKEN,\n );\n expect(contextModuleMock.getFieldContext).toHaveBeenNthCalledWith(\n 2,\n {\n chainId: 1,\n address: \"0x232425262728292a2b2c2d2e2f30313233343536\",\n deviceModelId: DeviceModelId.STAX,\n },\n ClearSignContextType.TOKEN,\n );\n });\n });\n });\n });\n\n describe(\"when context has no reference\", () => {\n it(\"should return context with empty subcontextCallbacks\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TOKEN,\n payload: \"test payload\",\n };\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"when context has reference but no valuePath\", () => {\n it(\"should return context with empty subcontextCallbacks\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: undefined as unknown as GenericPath,\n },\n };\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"error handling\", () => {\n it(\"should throw error for uncovered context type\", () => {\n // GIVEN\n const context = {\n type: \"UNKNOWN_TYPE\" as ClearSignContextSuccess[\"type\"],\n payload: \"test payload\",\n } as ClearSignContextSuccess;\n const args = { ...defaultArgs, context };\n\n // WHEN / THEN\n expect(() => new BuildSubcontextsTask(apiMock, args).run()).toThrow(\n \"Uncovered type: UNKNOWN_TYPE\",\n );\n });\n\n it(\"should throw error for uncovered reference type\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: \"UNKNOWN_REFERENCE_TYPE\" as ClearSignContextReference[\"type\"],\n } as ClearSignContextReference,\n };\n const args = { ...defaultArgs, context };\n\n // WHEN / THEN\n expect(() => new BuildSubcontextsTask(apiMock, args).run()).toThrow(\n \"Uncovered reference type: UNKNOWN_REFERENCE_TYPE\",\n );\n });\n });\n\n describe(\"CALLDATA reference type\", () => {\n it(\"should return empty subcontextCallbacks for CALLDATA reference\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.CALLDATA,\n callee: [{ type: \"TUPLE\", offset: 0 }],\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"references without valuePath\", () => {\n it(\"should return empty subcontextCallbacks for ENUM reference without valuePath\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.ENUM,\n id: 1,\n valuePath: undefined as unknown as GenericPath,\n },\n };\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n\n it(\"should return empty subcontextCallbacks for TRUSTED_NAME reference without valuePath\", () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TRUSTED_NAME,\n types: [\"type1\"],\n sources: [\"source1\"],\n valuePath: undefined as unknown as GenericPath,\n },\n };\n const args = { ...defaultArgs, context };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(0);\n });\n });\n\n describe(\"PROXY_INFO context type\", () => {\n beforeEach(() => {\n apiMock.sendCommand.mockResolvedValue(\n CommandResultFactory({ data: { challenge: \"test-challenge\" } }),\n );\n });\n\n it(\"should create callback to get proxy delegate call context\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"proxy payload\",\n };\n const args = {\n ...defaultArgs,\n context,\n subset: {\n ...defaultArgs.subset,\n to: \"0x1234567890123456789012345678901234567890\",\n data: \"0xabcdef\",\n },\n };\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.PROXY_INFO,\n payload: \"proxy result\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n\n expect(callbackResult).toEqual({\n type: ClearSignContextType.PROXY_INFO,\n payload: \"proxy result\",\n });\n expect(apiMock.sendCommand).toHaveBeenCalledWith(\n expect.any(GetChallengeCommand),\n );\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n proxyAddress: \"0x1234567890123456789012345678901234567890\",\n calldata: \"0xabcdef\",\n deviceModelId: DeviceModelId.STAX,\n challenge: \"test-challenge\",\n },\n ClearSignContextType.PROXY_INFO,\n );\n });\n\n it(\"should handle challenge command failure\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"proxy payload\",\n };\n const args = {\n ...defaultArgs,\n context,\n subset: {\n ...defaultArgs.subset,\n to: \"0x1234567890123456789012345678901234567890\",\n data: \"0xabcdef\",\n },\n };\n const error = new UnknownDeviceExchangeError(\"Failed\");\n apiMock.sendCommand.mockResolvedValueOnce(\n CommandResultFactory({\n error,\n }),\n );\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n\n expect(callbackResult).toEqual({\n error: new Error(\"Failed to get challenge\"),\n type: ClearSignContextType.ERROR,\n });\n expect(apiMock.sendCommand).toHaveBeenCalledWith(\n expect.any(GetChallengeCommand),\n );\n expect(contextModuleMock.getFieldContext).not.toHaveBeenCalled();\n });\n\n it(\"should handle missing proxy address\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"proxy payload\",\n };\n const args = {\n ...defaultArgs,\n context,\n subset: {\n ...defaultArgs.subset,\n to: undefined,\n data: \"0xabcdef\",\n },\n };\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n\n expect(callbackResult).toEqual({\n error: new Error(\"Failed to get proxy address\"),\n type: ClearSignContextType.ERROR,\n });\n expect(apiMock.sendCommand).toHaveBeenCalledWith(\n expect.any(GetChallengeCommand),\n );\n expect(contextModuleMock.getFieldContext).not.toHaveBeenCalled();\n });\n\n it(\"should use correct device model id in context\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.PROXY_INFO,\n payload: \"proxy payload\",\n };\n const args = {\n ...defaultArgs,\n context,\n deviceModelId: DeviceModelId.NANO_SP,\n subset: {\n ...defaultArgs.subset,\n to: \"0x1234567890123456789012345678901234567890\",\n data: \"0xabcdef\",\n },\n };\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.PROXY_INFO,\n payload: \"proxy result\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n await callback();\n\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n proxyAddress: \"0x1234567890123456789012345678901234567890\",\n calldata: \"0xabcdef\",\n deviceModelId: DeviceModelId.NANO_SP,\n challenge: \"test-challenge\",\n },\n ClearSignContextType.PROXY_INFO,\n );\n });\n });\n\n describe(\"edge cases\", () => {\n it(\"should handle value array shorter than 20 bytes for address extraction\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [new Uint8Array([0x01, 0x02, 0x03])]; // Only 3 bytes\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.ERROR,\n message: \"Invalid address\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.ERROR,\n message: \"Invalid address\",\n });\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n address: \"0x010203\",\n deviceModelId: DeviceModelId.STAX,\n },\n ClearSignContextType.TOKEN,\n );\n });\n\n it(\"should handle empty value array\", async () => {\n // GIVEN\n const context: ClearSignContextSuccess = {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"test payload\",\n reference: {\n type: ClearSignContextReferenceType.TOKEN,\n valuePath: [{ type: \"TUPLE\", offset: 0 }],\n },\n };\n const args = { ...defaultArgs, context };\n const extractedValues = [new Uint8Array([])]; // Empty array\n transactionParserMock.extractValue.mockReturnValue(\n Right(extractedValues),\n );\n contextModuleMock.getFieldContext.mockResolvedValue({\n type: ClearSignContextType.TOKEN,\n payload: \"token result\",\n });\n\n // WHEN\n const result = new BuildSubcontextsTask(apiMock, args).run();\n\n // THEN\n expect(result.subcontextCallbacks).toHaveLength(1);\n\n // Verify the callback calls getContext with empty address\n const callback = result.subcontextCallbacks[0]!;\n const callbackResult = await callback();\n expect(callbackResult).toEqual({\n type: ClearSignContextType.TOKEN,\n payload: \"token result\",\n });\n expect(contextModuleMock.getFieldContext).toHaveBeenCalledWith(\n {\n chainId: 1,\n address: \"0x\",\n deviceModelId: DeviceModelId.STAX,\n },\n ClearSignContextType.TOKEN,\n );\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAEE,iCAAAA,EAEA,wBAAAC,MAGK,2BACP,OACE,wBAAAC,EACA,iBAAAC,EACA,8BAAAC,MACK,kCACP,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAE5B,OAAS,uBAAAC,MAA2B,mDACpC,OAAS,mCAAAC,MAAuC,oEAGhD,OACE,wBAAAC,MAEK,yBAEP,SAAS,uBAAwB,IAAM,CACrC,MAAMC,EAAoB,CACxB,gBAAiB,GAAG,GAAG,CACzB,EACMC,EAAwB,CAC5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AA8B,MACpC,UAAW,CAAC,CAAE,KAAM,QAAS,OAAQ,CAAE,CAAC,CAC1C,CACF,EACMgB,EAAO,CAAE,GAAGH,EAAa,QAAAK,CAAQ,EACjCM,EAAkB,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,EAC3Cb,EAAsB,aAAa,gBACjCL,EAAMkB,CAAe,CACvB,EACAd,EAAkB,gBAAgB,kBAAkB,CAClD,KAAMT,EAAqB,MAC3B,QAAS,cACX,CAAC,EAGD,MAAMgB,EAAS,IAAIR,EAAqBG,EAASI,CAAI,EAAE,IAAI,EAG3D,OAAOC,EAAO,mBAAmB,EAAE,aAAa,CAAC,EAGjD,MAAMG,EAAWH,EAAO,oBAAoB,CAAC,EACvCQ,EAAiB,MAAML,EAAS,EACtC,OAAOK,CAAc,EAAE,QAAQ,CAC7B,KAAMxB,EAAqB,MAC3B,QAAS,cACX,CAAC,EACD,OAAOS,EAAkB,eAAe,EAAE,qBACxC,CACE,QAAS,EACT,QAAS,KACT,cAAeP,EAAc,IAC/B,EACAF,EAAqB,KACvB,CACF,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
6
|
"names": ["ClearSignContextReferenceType", "ClearSignContextType", "CommandResultFactory", "DeviceModelId", "UnknownDeviceExchangeError", "Left", "Right", "GetChallengeCommand", "makeDeviceActionInternalApiMock", "BuildSubcontextsTask", "contextModuleMock", "transactionParserMock", "apiMock", "defaultArgs", "simpleTypes", "type", "args", "result", "context", "expectedContext", "callback", "enumContext1", "enumContext2", "enumContext3", "extractedValues", "callbackResult", "callback1", "callback2", "callbackResult1", "callbackResult2", "enumContext", "error"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{TypedDataCalldataParamPresence as h,VERIFYING_CONTRACT_TOKEN_INDEX as k}from"@ledgerhq/context-module";import{ClearSignContextType as r}from"@ledgerhq/context-module";import{bufferToHexaString as D,CommandResultFactory as b,isSuccessCommandResult as m,LoadCertificateCommand as F}from"@ledgerhq/device-management-kit";import{Just as y,Maybe as g,Nothing as u}from"purify-ts";import{GetChallengeCommand as M}from"../../app-binder/command/GetChallengeCommand";import{ProvideProxyInfoCommand as O}from"../../app-binder/command/ProvideProxyInfoCommand";import{ProvideTokenInformationCommand as _}from"../../app-binder/command/ProvideTokenInformationCommand";import{ProvideTrustedNameCommand as V}from"../../app-binder/command/ProvideTrustedNameCommand";import{ProvideWeb3CheckCommand as U}from"../../app-binder/command/ProvideWeb3CheckCommand";import{CalldataParamPresence as x,Eip712FilterType as d,SendEIP712FilteringCommand as l}from"../../app-binder/command/SendEIP712FilteringCommand";import{SendEIP712StructDefinitionCommand as N,StructDefinitionCommand as P}from"../../app-binder/command/SendEIP712StructDefinitionCommand";import{StructImplemType as f}from"../../app-binder/command/SendEIP712StructImplemCommand";import{SendEIP712StructImplemTask as I}from"../../app-binder/task/SendEIP712StructImplemTask";import{TypedDataValueField as J}from"../../typed-data/model/Types";import{TypedDataValueArray as E,TypedDataValueRoot as W}from"../../typed-data/model/Types";import{ProvideTransactionContextsTask as G}from"./ProvideTransactionContextsTask";import{SendPayloadInChunksTask as T}from"./SendPayloadInChunksTask";const R=5;class oe{constructor(e,t,a,s=n=>new G(this.api,n)){this.api=e;this.contextModule=t;this.args=a;this.provideContextFactory=s;for(const n of this.args.domain)if(n.path==="chainId"&&n.value instanceof J){const i=BigInt(D(n.value.data));i<=Number.MAX_SAFE_INTEGER&&(this.chainId=y(Number(i)));break}}chainId=u;calldataMetadatas={};async run(){this.args.transactionChecks&&await this.provideContext(this.args.transactionChecks);const e=this.args.clearSignContext.extract()?.proxy;e!==void 0&&await this.provideContext(e);const t=b({data:void 0}),a=Object.entries(this.args.types).sort(([n],[i])=>n.localeCompare(i));for(const[n,i]of a){const o=await this.api.sendCommand(new N({command:P.Name,name:n}));if(!m(o))return o;for(const[c,w]of Object.entries(i)){const C=await this.api.sendCommand(new N({command:P.Field,name:c,type:w}));if(!m(C))return C}}if(this.args.clearSignContext.isJust()){const n=await this.api.sendCommand(new l({type:d.Activation}));if(!m(n))return n}for(const n of this.args.domain){const o=await this.getImplementationTask(n).run();if(!m(o))return o}if(this.args.clearSignContext.isJust()){const n=this.args.clearSignContext.extract(),i=await this.api.sendCommand(new l({type:d.MessageInfo,displayName:n.messageInfo.displayName,filtersCount:n.messageInfo.filtersCount,signature:n.messageInfo.signature}));if(!m(i))return i}const s={indexes:{},nextIndex:0};for(const n of this.args.message){const i=await this.provideTokenInformation(n,s);if(i.isJust())return i.extract();const o=await this.provideTrustedName(n);if(o.isJust())return o.extract();const c=await this.filterValue(n,s);if(c.isJust()&&!m(c.extract()))return c.extract();const C=await this.getImplementationTask(n).run();if(!m(C))return C;if(await this.tryProvideTransactionContext(),this.args.clearSignContext.isJust()&&n.value instanceof E&&n.value.length===0){const A=Object.entries(this.args.clearSignContext.extract().filters).filter(([p])=>p.startsWith(`${n.path}.[]`)).map(([,p])=>p);for(const p of A){const v=await this.api.sendCommand(new l({type:d.DiscardedPath,path:p.path}));if(!m(v))return v;const S=await this.provideFiltering(p,s,!0);if(!m(S))return S}}}return t}async provideContext({type:e,payload:t,certificate:a}){switch(a&&await this.api.sendCommand(new F({keyUsage:a.keyUsageNumber,certificate:a.payload})),e){case r.TRANSACTION_CHECK:await new T(this.api,{payload:t,commandFactory:s=>new U({payload:s.chunkedData,isFirstChunk:s.isFirstChunk})}).run();break;case r.PROXY_INFO:await new T(this.api,{payload:t,commandFactory:s=>new O({data:s.chunkedData,isFirstChunk:s.isFirstChunk})}).run();break;case r.TOKEN:case r.NFT:case r.TRUSTED_NAME:case r.PLUGIN:case r.EXTERNAL_PLUGIN:case r.ENUM:case r.TRANSACTION_INFO:case r.TRANSACTION_FIELD_DESCRIPTION:case r.DYNAMIC_NETWORK:case r.DYNAMIC_NETWORK_ICON:case r.SAFE:case r.SIGNER:throw new Error(`Context type ${e} not supported in EIP712 messages`);default:{const s=e;throw new Error(`Unhandled context type ${s}`)}}}getImplementationTask(e){return e.value instanceof W?new I(this.api,{type:f.ROOT,value:e.value.root}):e.value instanceof E?new I(this.api,{type:f.ARRAY,value:e.value.length}):new I(this.api,{type:f.FIELD,value:e.value.data})}async provideTokenInformation(e,t){if(this.args.clearSignContext.isJust()){const a=this.args.clearSignContext.extract().filters[e.path];if(a!==void 0&&(a.type==="amount"||a.type==="token")&&t.indexes[a.tokenIndex]===void 0){const s=a.tokenIndex,i=this.args.clearSignContext.extract().tokens[s];if(i===void 0)return u;const o=await this.api.sendCommand(new _({payload:i}));if(!m(o))return g.of(o);let{tokenIndex:c}=o.data;t.nextIndex=(c+1)%R,Number(s)===k&&(c=k),t.indexes[Number(s)]=c}}return u}async provideTrustedName(e){if(this.args.clearSignContext.isJust()&&this.chainId.isJust()){const t=this.args.clearSignContext.extract(),a=t.filters[e.path],s=t.trustedNamesAddresses[e.path];if(a!==void 0&&a.type==="trusted-name"&&s!==void 0){const n=await this.api.sendCommand(new M);if(!m(n))return y(n);const i=await this.contextModule.getFieldContext({chainId:this.chainId.extract(),address:s,challenge:n.data.challenge,types:a.types,sources:a.sources,deviceModelId:this.args.deviceModelId},r.TRUSTED_NAME);if(i.type===r.TRUSTED_NAME){i.certificate&&await this.api.sendCommand(new F({keyUsage:i.certificate.keyUsageNumber,certificate:i.certificate.payload}));const o=await new T(this.api,{payload:i.payload,commandFactory:c=>new V({data:c.chunkedData,isFirstChunk:c.isFirstChunk})}).run();if(!m(o))return y(o)}}}return u}async filterValue(e,t){if(this.args.clearSignContext.isJust()){const a=this.args.clearSignContext.extract().filters[e.path];if(a===void 0)return u;const s=await this.provideFiltering(a,t,!1);return g.of(s)}return u}async provideFiltering(e,t,a){switch(e.type){case"trusted-name":return await this.api.sendCommand(new l({type:d.TrustedName,discarded:a,displayName:e.displayName,typesAndSourcesPayload:e.typesAndSourcesPayload,signature:e.signature}));case"datetime":return await this.api.sendCommand(new l({type:d.Datetime,discarded:a,displayName:e.displayName,signature:e.signature}));case"raw":return await this.api.sendCommand(new l({type:d.Raw,discarded:a,displayName:e.displayName,signature:e.signature}));case"token":return this.sanitizeDeviceIndex(e.tokenIndex,t),await this.api.sendCommand(new l({type:d.Token,discarded:a,tokenIndex:t.indexes[e.tokenIndex],signature:e.signature}));case"amount":return this.sanitizeDeviceIndex(e.tokenIndex,t),await this.api.sendCommand(new l({type:d.Amount,discarded:a,displayName:e.displayName,tokenIndex:t.indexes[e.tokenIndex],signature:e.signature}));case"calldata-value":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new l({type:d.CalldataValue,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-callee":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new l({type:d.CalldataCallee,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-spender":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new l({type:d.CalldataSpender,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-chain-id":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new l({type:d.CalldataChainId,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-selector":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new l({type:d.CalldataSelector,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-amount":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new l({type:d.CalldataAmount,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));default:{const s=e;throw new Error(`ProvideEIP712ContextTask/provideFiltering - Unhandled filter ${s}`)}}}async provideCalldataInfos(e){if(this.args.clearSignContext.isJust()){if(this.calldataMetadatas[e]!==void 0)return this.calldataMetadatas[e].remainingFilters--,u;const t=this.args.clearSignContext.extract().calldatas[e];if(t===void 0)return u;const s=[t.filter.valueFlag,t.filter.calleeFlag===h.Present,t.filter.chainIdFlag,t.filter.selectorFlag,t.filter.amountFlag,t.filter.spenderFlag===h.Present].filter(n=>n).length;return this.calldataMetadatas[e]={remainingFilters:s-1,contexts:this.args.calldatasContexts[e]},g.of(await this.api.sendCommand(new l({type:d.CalldataInfo,discarded:!1,calldataIndex:e,valueFlag:t.filter.valueFlag,calleeFlag:this.mapCalldataPresence(t.filter.calleeFlag),chainIdFlag:t.filter.chainIdFlag,selectorFlag:t.filter.selectorFlag,amountFlag:t.filter.amountFlag,spenderFlag:this.mapCalldataPresence(t.filter.spenderFlag),signature:t.filter.signature})))}return u}async tryProvideTransactionContext(){for(const e in this.calldataMetadatas){const t=this.calldataMetadatas[e];t.remainingFilters===0&&(t.contexts!==void 0&&await this.provideContextFactory({contexts:t.contexts,derivationPath:this.args.derivationPath}).run(),delete this.calldataMetadatas[e])}}mapCalldataPresence(e){switch(e){case h.None:return x.None;case h.Present:return x.Present;case h.VerifyingContract:return x.VerifyingContract;default:{const t=e;throw new Error(`Unhandled presence ${t}`)}}}sanitizeDeviceIndex(e,t){t.indexes[e]===void 0&&(t.indexes[e]=t.nextIndex,t.nextIndex=(t.nextIndex+1)%R)}}export{oe as ProvideEIP712ContextTask};
|
|
1
|
+
import{TypedDataCalldataParamPresence as y,VERIFYING_CONTRACT_TOKEN_INDEX as N}from"@ledgerhq/context-module";import{ClearSignContextType as o}from"@ledgerhq/context-module";import{bufferToHexaString as b,CommandResultFactory as M,isSuccessCommandResult as m,LoadCertificateCommand as g}from"@ledgerhq/device-management-kit";import{Just as f,Maybe as x,Nothing as u}from"purify-ts";import{GetChallengeCommand as O}from"../../app-binder/command/GetChallengeCommand";import{ProvideProxyInfoCommand as _}from"../../app-binder/command/ProvideProxyInfoCommand";import{ProvideTokenInformationCommand as V}from"../../app-binder/command/ProvideTokenInformationCommand";import{ProvideTrustedNameCommand as U}from"../../app-binder/command/ProvideTrustedNameCommand";import{ProvideWeb3CheckCommand as J}from"../../app-binder/command/ProvideWeb3CheckCommand";import{CalldataParamPresence as I,Eip712FilterType as l,SendEIP712FilteringCommand as c}from"../../app-binder/command/SendEIP712FilteringCommand";import{SendEIP712StructDefinitionCommand as F,StructDefinitionCommand as E}from"../../app-binder/command/SendEIP712StructDefinitionCommand";import{StructImplemType as T}from"../../app-binder/command/SendEIP712StructImplemCommand";import{SendEIP712StructImplemTask as w}from"../../app-binder/task/SendEIP712StructImplemTask";import{TypedDataValueField as W}from"../../typed-data/model/Types";import{TypedDataValueArray as R,TypedDataValueRoot as G}from"../../typed-data/model/Types";import{ProvideTransactionContextsTask as L}from"./ProvideTransactionContextsTask";import{SendPayloadInChunksTask as v}from"./SendPayloadInChunksTask";const A=5;class de{constructor(e,t,a,s=r=>new L(this.api,r)){this.api=e;this.contextModule=t;this.args=a;this.provideContextFactory=s;for(const r of this.args.domain)if(r.path==="chainId"&&r.value instanceof W){const n=BigInt(b(r.value.data));n<=Number.MAX_SAFE_INTEGER&&(this.chainId=f(Number(n)));break}}chainId=u;calldataMetadatas={};async run(){this.args.transactionChecks&&await this.provideContext(this.args.transactionChecks);const e=this.args.clearSignContext.extract()?.proxy;e!==void 0&&await this.provideContext(e);const t=this.args.clearSignContext.extract()?.certificate;t!==void 0&&await this.api.sendCommand(new g({keyUsage:t.keyUsageNumber,certificate:t.payload}));const a=M({data:void 0}),s=Object.entries(this.args.types).sort(([n],[i])=>n.localeCompare(i));for(const[n,i]of s){const d=await this.api.sendCommand(new F({command:E.Name,name:n}));if(!m(d))return d;for(const[C,S]of Object.entries(i)){const h=await this.api.sendCommand(new F({command:E.Field,name:C,type:S}));if(!m(h))return h}}if(this.args.clearSignContext.isJust()){const n=await this.api.sendCommand(new c({type:l.Activation}));if(!m(n))return n}for(const n of this.args.domain){const d=await this.getImplementationTask(n).run();if(!m(d))return d}if(this.args.clearSignContext.isJust()){const n=this.args.clearSignContext.extract(),i=await this.api.sendCommand(new c({type:l.MessageInfo,displayName:n.messageInfo.displayName,filtersCount:n.messageInfo.filtersCount,signature:n.messageInfo.signature}));if(!m(i))return i}const r={indexes:{},nextIndex:0};for(const n of this.args.message){const i=await this.provideTokenInformation(n,r);if(i.isJust())return i.extract();const d=await this.provideTrustedName(n);if(d.isJust())return d.extract();const C=await this.filterValue(n,r);if(C.isJust()&&!m(C.extract()))return C.extract();const h=await this.getImplementationTask(n).run();if(!m(h))return h;if(await this.tryProvideTransactionContext(),this.args.clearSignContext.isJust()&&n.value instanceof R&&n.value.length===0){const D=Object.entries(this.args.clearSignContext.extract().filters).filter(([p])=>p.startsWith(`${n.path}.[]`)).map(([,p])=>p);for(const p of D){const k=await this.api.sendCommand(new c({type:l.DiscardedPath,path:p.path}));if(!m(k))return k;const P=await this.provideFiltering(p,r,!0);if(!m(P))return P}}}return a}async provideContext({type:e,payload:t,certificate:a}){switch(a&&await this.api.sendCommand(new g({keyUsage:a.keyUsageNumber,certificate:a.payload})),e){case o.TRANSACTION_CHECK:await new v(this.api,{payload:t,commandFactory:s=>new J({payload:s.chunkedData,isFirstChunk:s.isFirstChunk})}).run();break;case o.PROXY_INFO:await new v(this.api,{payload:t,commandFactory:s=>new _({data:s.chunkedData,isFirstChunk:s.isFirstChunk})}).run();break;case o.TOKEN:case o.NFT:case o.TRUSTED_NAME:case o.PLUGIN:case o.EXTERNAL_PLUGIN:case o.ENUM:case o.TRANSACTION_INFO:case o.TRANSACTION_FIELD_DESCRIPTION:case o.DYNAMIC_NETWORK:case o.DYNAMIC_NETWORK_ICON:case o.SAFE:case o.SIGNER:throw new Error(`Context type ${e} not supported in EIP712 messages`);default:{const s=e;throw new Error(`Unhandled context type ${s}`)}}}getImplementationTask(e){return e.value instanceof G?new w(this.api,{type:T.ROOT,value:e.value.root}):e.value instanceof R?new w(this.api,{type:T.ARRAY,value:e.value.length}):new w(this.api,{type:T.FIELD,value:e.value.data})}async provideTokenInformation(e,t){if(this.args.clearSignContext.isJust()){const a=this.args.clearSignContext.extract().filters[e.path];if(a!==void 0&&(a.type==="amount"||a.type==="token")&&t.indexes[a.tokenIndex]===void 0){const s=a.tokenIndex,n=this.args.clearSignContext.extract().tokens[s];if(n===void 0)return u;const i=await this.api.sendCommand(new V({payload:n}));if(!m(i))return x.of(i);let{tokenIndex:d}=i.data;t.nextIndex=(d+1)%A,Number(s)===N&&(d=N),t.indexes[Number(s)]=d}}return u}async provideTrustedName(e){if(this.args.clearSignContext.isJust()&&this.chainId.isJust()){const t=this.args.clearSignContext.extract(),a=t.filters[e.path],s=t.trustedNamesAddresses[e.path];if(a!==void 0&&a.type==="trusted-name"&&s!==void 0){const r=await this.api.sendCommand(new O);if(!m(r))return f(r);const n=await this.contextModule.getFieldContext({chainId:this.chainId.extract(),address:s,challenge:r.data.challenge,types:a.types,sources:a.sources,deviceModelId:this.args.deviceModelId},o.TRUSTED_NAME);if(n.type===o.TRUSTED_NAME){n.certificate&&await this.api.sendCommand(new g({keyUsage:n.certificate.keyUsageNumber,certificate:n.certificate.payload}));const i=await new v(this.api,{payload:n.payload,commandFactory:d=>new U({data:d.chunkedData,isFirstChunk:d.isFirstChunk})}).run();if(!m(i))return f(i)}}}return u}async filterValue(e,t){if(this.args.clearSignContext.isJust()){const a=this.args.clearSignContext.extract().filters[e.path];if(a===void 0)return u;const s=await this.provideFiltering(a,t,!1);return x.of(s)}return u}async provideFiltering(e,t,a){switch(e.type){case"trusted-name":return await this.api.sendCommand(new c({type:l.TrustedName,discarded:a,displayName:e.displayName,typesAndSourcesPayload:e.typesAndSourcesPayload,signature:e.signature}));case"datetime":return await this.api.sendCommand(new c({type:l.Datetime,discarded:a,displayName:e.displayName,signature:e.signature}));case"raw":return await this.api.sendCommand(new c({type:l.Raw,discarded:a,displayName:e.displayName,signature:e.signature}));case"token":return this.sanitizeDeviceIndex(e.tokenIndex,t),await this.api.sendCommand(new c({type:l.Token,discarded:a,tokenIndex:t.indexes[e.tokenIndex],signature:e.signature}));case"amount":return this.sanitizeDeviceIndex(e.tokenIndex,t),await this.api.sendCommand(new c({type:l.Amount,discarded:a,displayName:e.displayName,tokenIndex:t.indexes[e.tokenIndex],signature:e.signature}));case"calldata-value":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new c({type:l.CalldataValue,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-callee":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new c({type:l.CalldataCallee,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-spender":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new c({type:l.CalldataSpender,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-chain-id":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new c({type:l.CalldataChainId,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-selector":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new c({type:l.CalldataSelector,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));case"calldata-amount":return await this.provideCalldataInfos(e.calldataIndex),await this.api.sendCommand(new c({type:l.CalldataAmount,discarded:a,calldataIndex:e.calldataIndex,signature:e.signature}));default:{const s=e;throw new Error(`ProvideEIP712ContextTask/provideFiltering - Unhandled filter ${s}`)}}}async provideCalldataInfos(e){if(this.args.clearSignContext.isJust()){if(this.calldataMetadatas[e]!==void 0)return this.calldataMetadatas[e].remainingFilters--,u;const t=this.args.clearSignContext.extract().calldatas[e];if(t===void 0)return u;const s=[t.filter.valueFlag,t.filter.calleeFlag===y.Present,t.filter.chainIdFlag,t.filter.selectorFlag,t.filter.amountFlag,t.filter.spenderFlag===y.Present].filter(r=>r).length;return this.calldataMetadatas[e]={remainingFilters:s-1,contexts:this.args.calldatasContexts[e]},x.of(await this.api.sendCommand(new c({type:l.CalldataInfo,discarded:!1,calldataIndex:e,valueFlag:t.filter.valueFlag,calleeFlag:this.mapCalldataPresence(t.filter.calleeFlag),chainIdFlag:t.filter.chainIdFlag,selectorFlag:t.filter.selectorFlag,amountFlag:t.filter.amountFlag,spenderFlag:this.mapCalldataPresence(t.filter.spenderFlag),signature:t.filter.signature})))}return u}async tryProvideTransactionContext(){for(const e in this.calldataMetadatas){const t=this.calldataMetadatas[e];t.remainingFilters===0&&(t.contexts!==void 0&&await this.provideContextFactory({contexts:t.contexts,derivationPath:this.args.derivationPath}).run(),delete this.calldataMetadatas[e])}}mapCalldataPresence(e){switch(e){case y.None:return I.None;case y.Present:return I.Present;case y.VerifyingContract:return I.VerifyingContract;default:{const t=e;throw new Error(`Unhandled presence ${t}`)}}}sanitizeDeviceIndex(e,t){t.indexes[e]===void 0&&(t.indexes[e]=t.nextIndex,t.nextIndex=(t.nextIndex+1)%A)}}export{de as 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 ContextModule,\n type TypedDataCalldataIndex,\n TypedDataCalldataParamPresence,\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 DeviceModelId,\n InternalApi,\n} from \"@ledgerhq/device-management-kit\";\nimport {\n bufferToHexaString,\n CommandResultFactory,\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 { ProvideProxyInfoCommand } from \"@internal/app-binder/command/ProvideProxyInfoCommand\";\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 CalldataParamPresence,\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 { type ContextWithSubContexts } from \"@internal/app-binder/task/BuildFullContextsTask\";\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 {\n ProvideTransactionContextsTask,\n type ProvideTransactionContextsTaskArgs,\n} from \"./ProvideTransactionContextsTask\";\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 deviceModelId: DeviceModelId;\n derivationPath: string;\n types: Record<StructName, Record<FieldName, FieldType>>;\n domain: Array<TypedDataValue>;\n message: Array<TypedDataValue>;\n clearSignContext: Maybe<TypedDataClearSignContextSuccess>;\n calldatasContexts: Record<TypedDataCalldataIndex, ContextWithSubContexts[]>;\n transactionChecks?: ClearSignContextSuccess;\n};\n\nconst DEVICE_ASSETS_MAX = 5;\n\ntype DeviceAssetIndexes = {\n indexes: Record<TypedDataTokenIndex, number>;\n nextIndex: number;\n};\n\ntype CalldataFiltersMetadata = {\n remainingFilters: number;\n contexts?: ContextWithSubContexts[];\n};\n\nexport class ProvideEIP712ContextTask {\n private chainId: Maybe<number> = Nothing;\n private calldataMetadatas: Record<\n TypedDataCalldataIndex,\n CalldataFiltersMetadata\n > = {};\n\n constructor(\n private api: InternalApi,\n private contextModule: ContextModule,\n private args: ProvideEIP712ContextTaskArgs,\n private readonly provideContextFactory = (\n args: ProvideTransactionContextsTaskArgs,\n ) => new ProvideTransactionContextsTask(this.api, args),\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 // Provide the transaction checks first if any\n if (this.args.transactionChecks) {\n await this.provideContext(this.args.transactionChecks);\n }\n\n // Send proxy descriptor first if required\n const proxyContext:\n | ClearSignContextSuccess<ClearSignContextType.PROXY_INFO>\n | undefined = this.args.clearSignContext.extract()?.proxy;\n if (proxyContext !== undefined) {\n await this.provideContext(proxyContext);\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 a transaction was embedded in that value, provide the related clear sign context\n await this.tryProvideTransactionContext();\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 async provideContext({\n type,\n payload,\n certificate,\n }: ClearSignContextSuccess) {\n // if a certificate is provided, we load it before sending the command\n if (certificate) {\n await this.api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: certificate.keyUsageNumber,\n certificate: certificate.payload,\n }),\n );\n }\n\n switch (type) {\n case ClearSignContextType.TRANSACTION_CHECK:\n await new SendPayloadInChunksTask(this.api, {\n payload,\n commandFactory: (args) =>\n new ProvideWeb3CheckCommand({\n payload: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n break;\n case ClearSignContextType.PROXY_INFO:\n await new SendPayloadInChunksTask(this.api, {\n payload,\n commandFactory: (args) =>\n new ProvideProxyInfoCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n break;\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.ENUM:\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.SAFE:\n case ClearSignContextType.SIGNER:\n throw new Error(\n `Context type ${type} not supported in EIP712 messages`,\n );\n default: {\n const uncoveredType: never = type;\n throw new Error(`Unhandled context type ${uncoveredType}`);\n }\n }\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.getFieldContext(\n {\n chainId: this.chainId.extract(),\n address,\n challenge: getChallengeResult.data.challenge,\n types: filter.types,\n sources: filter.sources,\n deviceModelId: this.args.deviceModelId,\n },\n ClearSignContextType.TRUSTED_NAME,\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 case \"calldata-value\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataValue,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-callee\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataCallee,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-spender\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataSpender,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-chain-id\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataChainId,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-selector\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataSelector,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-amount\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataAmount,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n default: {\n const unhandledType: never = filter;\n throw new Error(\n `ProvideEIP712ContextTask/provideFiltering - Unhandled filter ${unhandledType}`,\n );\n }\n }\n }\n\n private async provideCalldataInfos(\n calldataIndex: number,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n // ensure the calldata info was not already provided to the device\n if (this.calldataMetadatas[calldataIndex] !== undefined) {\n // If already provided, update the remaining filters count\n this.calldataMetadatas[calldataIndex]!.remainingFilters--;\n return Nothing;\n }\n\n // get the calldata infos\n const calldataInfos =\n this.args.clearSignContext.extract().calldatas[calldataIndex];\n if (calldataInfos === undefined) {\n return Nothing;\n }\n\n // Initialize the expected filters count\n const filtersPresence = [\n calldataInfos.filter.valueFlag,\n calldataInfos.filter.calleeFlag ===\n TypedDataCalldataParamPresence.Present,\n calldataInfos.filter.chainIdFlag,\n calldataInfos.filter.selectorFlag,\n calldataInfos.filter.amountFlag,\n calldataInfos.filter.spenderFlag ===\n TypedDataCalldataParamPresence.Present,\n ];\n const filtersCount = filtersPresence.filter((f) => f).length;\n this.calldataMetadatas[calldataIndex] = {\n remainingFilters: filtersCount - 1, // Minus 1 since a filter is already being sent\n contexts: this.args.calldatasContexts[calldataIndex],\n };\n\n // provide the transaction infos filter\n return Maybe.of(\n await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataInfo,\n discarded: false,\n calldataIndex: calldataIndex,\n valueFlag: calldataInfos.filter.valueFlag,\n calleeFlag: this.mapCalldataPresence(\n calldataInfos.filter.calleeFlag,\n ),\n chainIdFlag: calldataInfos.filter.chainIdFlag,\n selectorFlag: calldataInfos.filter.selectorFlag,\n amountFlag: calldataInfos.filter.amountFlag,\n spenderFlag: this.mapCalldataPresence(\n calldataInfos.filter.spenderFlag,\n ),\n signature: calldataInfos.filter.signature,\n }),\n ),\n );\n }\n return Nothing;\n }\n\n private async tryProvideTransactionContext() {\n for (const calldataIndex in this.calldataMetadatas) {\n const metadata = this.calldataMetadatas[calldataIndex]!;\n if (metadata.remainingFilters === 0) {\n // All the filters and implementations were sent for that TX,\n // the related clear sign contexts should now be provided\n if (metadata.contexts !== undefined) {\n await this.provideContextFactory({\n contexts: metadata.contexts,\n derivationPath: this.args.derivationPath,\n }).run();\n }\n delete this.calldataMetadatas[calldataIndex];\n }\n }\n }\n\n private mapCalldataPresence(\n presence: TypedDataCalldataParamPresence,\n ): CalldataParamPresence {\n switch (presence) {\n case TypedDataCalldataParamPresence.None:\n return CalldataParamPresence.None;\n case TypedDataCalldataParamPresence.Present:\n return CalldataParamPresence.Present;\n case TypedDataCalldataParamPresence.VerifyingContract:\n return CalldataParamPresence.VerifyingContract;\n default: {\n const unhandledPresence: never = presence;\n throw new Error(`Unhandled presence ${unhandledPresence}`);\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": "AAAA,
|
|
6
|
-
"names": ["TypedDataCalldataParamPresence", "VERIFYING_CONTRACT_TOKEN_INDEX", "ClearSignContextType", "bufferToHexaString", "CommandResultFactory", "isSuccessCommandResult", "LoadCertificateCommand", "Just", "Maybe", "Nothing", "GetChallengeCommand", "ProvideProxyInfoCommand", "ProvideTokenInformationCommand", "ProvideTrustedNameCommand", "ProvideWeb3CheckCommand", "CalldataParamPresence", "Eip712FilterType", "SendEIP712FilteringCommand", "SendEIP712StructDefinitionCommand", "StructDefinitionCommand", "StructImplemType", "SendEIP712StructImplemTask", "TypedDataValueField", "TypedDataValueArray", "TypedDataValueRoot", "ProvideTransactionContextsTask", "SendPayloadInChunksTask", "DEVICE_ASSETS_MAX", "ProvideEIP712ContextTask", "api", "contextModule", "args", "provideContextFactory", "domainValue", "val", "proxyContext", "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", "type", "payload", "
|
|
4
|
+
"sourcesContent": ["import {\n type ContextModule,\n type PkiCertificate,\n type TypedDataCalldataIndex,\n TypedDataCalldataParamPresence,\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 DeviceModelId,\n InternalApi,\n} from \"@ledgerhq/device-management-kit\";\nimport {\n bufferToHexaString,\n CommandResultFactory,\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 { ProvideProxyInfoCommand } from \"@internal/app-binder/command/ProvideProxyInfoCommand\";\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 CalldataParamPresence,\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 { type ContextWithSubContexts } from \"@internal/app-binder/task/BuildFullContextsTask\";\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 {\n ProvideTransactionContextsTask,\n type ProvideTransactionContextsTaskArgs,\n} from \"./ProvideTransactionContextsTask\";\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 deviceModelId: DeviceModelId;\n derivationPath: string;\n types: Record<StructName, Record<FieldName, FieldType>>;\n domain: Array<TypedDataValue>;\n message: Array<TypedDataValue>;\n clearSignContext: Maybe<TypedDataClearSignContextSuccess>;\n calldatasContexts: Record<TypedDataCalldataIndex, ContextWithSubContexts[]>;\n transactionChecks?: ClearSignContextSuccess;\n};\n\nconst DEVICE_ASSETS_MAX = 5;\n\ntype DeviceAssetIndexes = {\n indexes: Record<TypedDataTokenIndex, number>;\n nextIndex: number;\n};\n\ntype CalldataFiltersMetadata = {\n remainingFilters: number;\n contexts?: ContextWithSubContexts[];\n};\n\nexport class ProvideEIP712ContextTask {\n private chainId: Maybe<number> = Nothing;\n private calldataMetadatas: Record<\n TypedDataCalldataIndex,\n CalldataFiltersMetadata\n > = {};\n\n constructor(\n private api: InternalApi,\n private contextModule: ContextModule,\n private args: ProvideEIP712ContextTaskArgs,\n private readonly provideContextFactory = (\n args: ProvideTransactionContextsTaskArgs,\n ) => new ProvideTransactionContextsTask(this.api, args),\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 // Provide the transaction checks first if any\n if (this.args.transactionChecks) {\n await this.provideContext(this.args.transactionChecks);\n }\n\n // Send proxy descriptor first if required\n const proxyContext:\n | ClearSignContextSuccess<ClearSignContextType.PROXY_INFO>\n | undefined = this.args.clearSignContext.extract()?.proxy;\n if (proxyContext !== undefined) {\n await this.provideContext(proxyContext);\n }\n\n // Send certificate if required\n const certificate: PkiCertificate | undefined =\n this.args.clearSignContext.extract()?.certificate;\n if (certificate !== undefined) {\n await this.api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: certificate.keyUsageNumber,\n certificate: certificate.payload,\n }),\n );\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 a transaction was embedded in that value, provide the related clear sign context\n await this.tryProvideTransactionContext();\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 async provideContext({\n type,\n payload,\n certificate,\n }: ClearSignContextSuccess) {\n // if a certificate is provided, we load it before sending the command\n if (certificate) {\n await this.api.sendCommand(\n new LoadCertificateCommand({\n keyUsage: certificate.keyUsageNumber,\n certificate: certificate.payload,\n }),\n );\n }\n\n switch (type) {\n case ClearSignContextType.TRANSACTION_CHECK:\n await new SendPayloadInChunksTask(this.api, {\n payload,\n commandFactory: (args) =>\n new ProvideWeb3CheckCommand({\n payload: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n break;\n case ClearSignContextType.PROXY_INFO:\n await new SendPayloadInChunksTask(this.api, {\n payload,\n commandFactory: (args) =>\n new ProvideProxyInfoCommand({\n data: args.chunkedData,\n isFirstChunk: args.isFirstChunk,\n }),\n }).run();\n break;\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.ENUM:\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.SAFE:\n case ClearSignContextType.SIGNER:\n throw new Error(\n `Context type ${type} not supported in EIP712 messages`,\n );\n default: {\n const uncoveredType: never = type;\n throw new Error(`Unhandled context type ${uncoveredType}`);\n }\n }\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.getFieldContext(\n {\n chainId: this.chainId.extract(),\n address,\n challenge: getChallengeResult.data.challenge,\n types: filter.types,\n sources: filter.sources,\n deviceModelId: this.args.deviceModelId,\n },\n ClearSignContextType.TRUSTED_NAME,\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 case \"calldata-value\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataValue,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-callee\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataCallee,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-spender\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataSpender,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-chain-id\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataChainId,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-selector\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataSelector,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n case \"calldata-amount\":\n await this.provideCalldataInfos(filter.calldataIndex);\n return await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataAmount,\n discarded,\n calldataIndex: filter.calldataIndex,\n signature: filter.signature,\n }),\n );\n default: {\n const unhandledType: never = filter;\n throw new Error(\n `ProvideEIP712ContextTask/provideFiltering - Unhandled filter ${unhandledType}`,\n );\n }\n }\n }\n\n private async provideCalldataInfos(\n calldataIndex: number,\n ): Promise<Maybe<CommandResult<AllSuccessTypes, EthErrorCodes>>> {\n if (this.args.clearSignContext.isJust()) {\n // ensure the calldata info was not already provided to the device\n if (this.calldataMetadatas[calldataIndex] !== undefined) {\n // If already provided, update the remaining filters count\n this.calldataMetadatas[calldataIndex]!.remainingFilters--;\n return Nothing;\n }\n\n // get the calldata infos\n const calldataInfos =\n this.args.clearSignContext.extract().calldatas[calldataIndex];\n if (calldataInfos === undefined) {\n return Nothing;\n }\n\n // Initialize the expected filters count\n const filtersPresence = [\n calldataInfos.filter.valueFlag,\n calldataInfos.filter.calleeFlag ===\n TypedDataCalldataParamPresence.Present,\n calldataInfos.filter.chainIdFlag,\n calldataInfos.filter.selectorFlag,\n calldataInfos.filter.amountFlag,\n calldataInfos.filter.spenderFlag ===\n TypedDataCalldataParamPresence.Present,\n ];\n const filtersCount = filtersPresence.filter((f) => f).length;\n this.calldataMetadatas[calldataIndex] = {\n remainingFilters: filtersCount - 1, // Minus 1 since a filter is already being sent\n contexts: this.args.calldatasContexts[calldataIndex],\n };\n\n // provide the transaction infos filter\n return Maybe.of(\n await this.api.sendCommand(\n new SendEIP712FilteringCommand({\n type: Eip712FilterType.CalldataInfo,\n discarded: false,\n calldataIndex: calldataIndex,\n valueFlag: calldataInfos.filter.valueFlag,\n calleeFlag: this.mapCalldataPresence(\n calldataInfos.filter.calleeFlag,\n ),\n chainIdFlag: calldataInfos.filter.chainIdFlag,\n selectorFlag: calldataInfos.filter.selectorFlag,\n amountFlag: calldataInfos.filter.amountFlag,\n spenderFlag: this.mapCalldataPresence(\n calldataInfos.filter.spenderFlag,\n ),\n signature: calldataInfos.filter.signature,\n }),\n ),\n );\n }\n return Nothing;\n }\n\n private async tryProvideTransactionContext() {\n for (const calldataIndex in this.calldataMetadatas) {\n const metadata = this.calldataMetadatas[calldataIndex]!;\n if (metadata.remainingFilters === 0) {\n // All the filters and implementations were sent for that TX,\n // the related clear sign contexts should now be provided\n if (metadata.contexts !== undefined) {\n await this.provideContextFactory({\n contexts: metadata.contexts,\n derivationPath: this.args.derivationPath,\n }).run();\n }\n delete this.calldataMetadatas[calldataIndex];\n }\n }\n }\n\n private mapCalldataPresence(\n presence: TypedDataCalldataParamPresence,\n ): CalldataParamPresence {\n switch (presence) {\n case TypedDataCalldataParamPresence.None:\n return CalldataParamPresence.None;\n case TypedDataCalldataParamPresence.Present:\n return CalldataParamPresence.Present;\n case TypedDataCalldataParamPresence.VerifyingContract:\n return CalldataParamPresence.VerifyingContract;\n default: {\n const unhandledPresence: never = presence;\n throw new Error(`Unhandled presence ${unhandledPresence}`);\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": "AAAA,OAIE,kCAAAA,EAIA,kCAAAC,MACK,2BACP,OAEE,wBAAAC,MACK,2BAMP,OACE,sBAAAC,EACA,wBAAAC,EACA,0BAAAC,EACA,0BAAAC,MACK,kCACP,OAAS,QAAAC,EAAM,SAAAC,EAAO,WAAAC,MAAe,YAErC,OAAS,uBAAAC,MAA2B,mDACpC,OAAS,2BAAAC,MAA+B,uDACxC,OAAS,kCAAAC,MAAsC,8DAC/C,OAAS,6BAAAC,MAAiC,yDAC1C,OAAS,2BAAAC,MAA+B,uDACxC,OACE,yBAAAC,EACA,oBAAAC,EACA,8BAAAC,MACK,0DACP,OACE,qCAAAC,EACA,2BAAAC,MACK,iEACP,OAAS,oBAAAC,MAAwB,6DAGjC,OAAS,8BAAAC,MAAkC,uDAC3C,OAAS,uBAAAC,MAA2B,mCACpC,OAKE,uBAAAC,EACA,sBAAAC,MACK,mCAEP,OACE,kCAAAC,MAEK,mCACP,OAAS,2BAAAC,MAA+B,4BAmBxC,MAAMC,EAAoB,EAYnB,MAAMC,EAAyB,CAOpC,YACUC,EACAC,EACAC,EACSC,EACfD,GACG,IAAIN,EAA+B,KAAK,IAAKM,CAAI,EACtD,CANQ,SAAAF,EACA,mBAAAC,EACA,UAAAC,EACS,2BAAAC,EAIjB,UAAWC,KAAe,KAAK,KAAK,OAClC,GACEA,EAAY,OAAS,WACrBA,EAAY,iBAAiBX,EAC7B,CACA,MAAMY,EAAM,OAAO/B,EAAmB8B,EAAY,MAAM,IAAI,CAAC,EACzDC,GAAO,OAAO,mBAChB,KAAK,QAAU3B,EAAK,OAAO2B,CAAG,CAAC,GAEjC,KACF,CAEJ,CA1BQ,QAAyBzB,EACzB,kBAG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C/B,KAAKf,EAA+B,QAClC,OAAOe,EAAsB,QAC/B,KAAKf,EAA+B,kBAClC,OAAOe,EAAsB,kBAC/B,QAAS,CACP,MAAMmE,EAA2BD,EACjC,MAAM,IAAI,MAAM,sBAAsBC,CAAiB,EAAE,CAC3D,CACF,CACF,CAEQ,oBACNjB,EACAb,EACA,CAEIA,EAAc,QAAQa,CAAe,IAAM,SAC7Cb,EAAc,QAAQa,CAAe,EAAIb,EAAc,UACvDA,EAAc,WACXA,EAAc,UAAY,GAAKzB,EAEtC,CACF",
|
|
6
|
+
"names": ["TypedDataCalldataParamPresence", "VERIFYING_CONTRACT_TOKEN_INDEX", "ClearSignContextType", "bufferToHexaString", "CommandResultFactory", "isSuccessCommandResult", "LoadCertificateCommand", "Just", "Maybe", "Nothing", "GetChallengeCommand", "ProvideProxyInfoCommand", "ProvideTokenInformationCommand", "ProvideTrustedNameCommand", "ProvideWeb3CheckCommand", "CalldataParamPresence", "Eip712FilterType", "SendEIP712FilteringCommand", "SendEIP712StructDefinitionCommand", "StructDefinitionCommand", "StructImplemType", "SendEIP712StructImplemTask", "TypedDataValueField", "TypedDataValueArray", "TypedDataValueRoot", "ProvideTransactionContextsTask", "SendPayloadInChunksTask", "DEVICE_ASSETS_MAX", "ProvideEIP712ContextTask", "api", "contextModule", "args", "provideContextFactory", "domainValue", "val", "proxyContext", "certificate", "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", "type", "payload", "uncoveredType", "descriptorIndex", "token", "provideTokenInfoResult", "deviceIndex", "context", "address", "getChallengeResult", "provideNameResult", "filteringResult", "discarded", "unhandledType", "calldataIndex", "calldataInfos", "filtersCount", "f", "metadata", "presence", "unhandledPresence"]
|
|
7
7
|
}
|