@ledgerhq/device-signer-kit-ethereum 0.0.0-multisig-20250910160951 → 0.0.0-multisig-2-20250922093851

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js +1 -1
  2. package/lib/cjs/api/app-binder/SignTransactionDeviceActionTypes.js.map +2 -2
  3. package/lib/cjs/api/index.js +1 -1
  4. package/lib/cjs/api/index.js.map +3 -3
  5. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  6. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
  7. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
  8. package/lib/cjs/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +3 -3
  9. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.js +1 -1
  10. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.js.map +3 -3
  11. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.test.js +1 -1
  12. package/lib/cjs/internal/app-binder/task/BuildBaseContexts.test.js.map +2 -2
  13. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.js +1 -1
  14. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.js.map +2 -2
  15. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.test.js +1 -1
  16. package/lib/cjs/internal/app-binder/task/BuildFullContextsTask.test.js.map +2 -2
  17. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
  18. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.js.map +3 -3
  19. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.test.js +1 -1
  20. package/lib/cjs/internal/app-binder/task/BuildSubcontextsTask.test.js.map +3 -3
  21. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js +1 -1
  22. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.js.map +2 -2
  23. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js +1 -1
  24. package/lib/cjs/internal/app-binder/task/ProvideContextsTask.test.js.map +2 -2
  25. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
  26. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
  27. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
  28. package/lib/cjs/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +2 -2
  29. package/lib/cjs/package.json +1 -1
  30. package/lib/esm/api/app-binder/SignTransactionDeviceActionTypes.js +1 -1
  31. package/lib/esm/api/app-binder/SignTransactionDeviceActionTypes.js.map +2 -2
  32. package/lib/esm/api/index.js +1 -1
  33. package/lib/esm/api/index.js.map +2 -2
  34. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js +1 -1
  35. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.js.map +3 -3
  36. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js +1 -1
  37. package/lib/esm/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.js.map +3 -3
  38. package/lib/esm/internal/app-binder/task/BuildBaseContexts.js +1 -1
  39. package/lib/esm/internal/app-binder/task/BuildBaseContexts.js.map +3 -3
  40. package/lib/esm/internal/app-binder/task/BuildBaseContexts.test.js +1 -1
  41. package/lib/esm/internal/app-binder/task/BuildBaseContexts.test.js.map +2 -2
  42. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.js +1 -1
  43. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.js.map +2 -2
  44. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.test.js +1 -1
  45. package/lib/esm/internal/app-binder/task/BuildFullContextsTask.test.js.map +2 -2
  46. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js +1 -1
  47. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.js.map +3 -3
  48. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.test.js +1 -1
  49. package/lib/esm/internal/app-binder/task/BuildSubcontextsTask.test.js.map +3 -3
  50. package/lib/esm/internal/app-binder/task/ProvideContextsTask.js +1 -1
  51. package/lib/esm/internal/app-binder/task/ProvideContextsTask.js.map +2 -2
  52. package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js +1 -1
  53. package/lib/esm/internal/app-binder/task/ProvideContextsTask.test.js.map +2 -2
  54. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js +1 -1
  55. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.js.map +3 -3
  56. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js +1 -1
  57. package/lib/esm/internal/app-binder/task/ProvideEIP712ContextTask.test.js.map +2 -2
  58. package/lib/esm/package.json +1 -1
  59. package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts +2 -1
  60. package/lib/types/api/app-binder/SignTransactionDeviceActionTypes.d.ts.map +1 -1
  61. package/lib/types/api/index.d.ts +5 -9
  62. package/lib/types/api/index.d.ts.map +1 -1
  63. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts +1 -1
  64. package/lib/types/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.d.ts.map +1 -1
  65. package/lib/types/internal/app-binder/task/BuildBaseContexts.d.ts +14 -1
  66. package/lib/types/internal/app-binder/task/BuildBaseContexts.d.ts.map +1 -1
  67. package/lib/types/internal/app-binder/task/BuildFullContextsTask.d.ts.map +1 -1
  68. package/lib/types/internal/app-binder/task/BuildSubcontextsTask.d.ts.map +1 -1
  69. package/lib/types/internal/app-binder/task/ProvideContextsTask.d.ts +3 -1
  70. package/lib/types/internal/app-binder/task/ProvideContextsTask.d.ts.map +1 -1
  71. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts +1 -1
  72. package/lib/types/internal/app-binder/task/ProvideEIP712ContextTask.d.ts.map +1 -1
  73. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  74. package/package.json +6 -6
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/app-binder/device-action/SignTransaction/SignTransactionDeviceAction.test.ts"],
4
- "sourcesContent": ["/* eslint @typescript-eslint/consistent-type-imports: 0 */\nimport {\n ClearSignContextType,\n type ContextModule,\n TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceActionState,\n DeviceActionStatus,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n InvalidStatusWordError,\n TransportDeviceModel,\n UserInteractionRequired,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\nimport { Just } from \"purify-ts\";\nimport { lastValueFrom, Observable } from \"rxjs\";\n\nimport {\n SignTransactionDAError,\n SignTransactionDAIntermediateValue,\n type SignTransactionDAState,\n SignTransactionDAStep,\n} from \"@api/app-binder/SignTransactionDeviceActionTypes\";\nimport { Signature } from \"@api/index\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { TransactionType } from \"@api/model/TransactionType\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { setupOpenAppDAMock } from \"@internal/app-binder/device-action/__test-utils__/setupOpenAppDAMock\";\nimport { executeUntilStep } from \"@internal/app-binder/device-action/__test-utils__/testDeviceActionUntilStep\";\nimport { ContextWithSubContexts } from \"@internal/app-binder/task/BuildFullContextsTask\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nimport { SignTransactionDeviceAction } from \"./SignTransactionDeviceAction\";\n\nvi.mock(\"@ledgerhq/device-management-kit\", async (importOriginal) => {\n const original =\n await importOriginal<typeof import(\"@ledgerhq/device-management-kit\")>();\n return {\n ...original,\n OpenAppDeviceAction: vi.fn(() => ({\n makeStateMachine: vi.fn(),\n })),\n };\n});\n\ndescribe(\"SignTransactionDeviceAction\", () => {\n let observable: Observable<\n DeviceActionState<\n Signature,\n SignTransactionDAError,\n SignTransactionDAIntermediateValue\n >\n >;\n const contextModuleMock: ContextModule = {\n getFieldContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n };\n const mapperMock: TransactionMapperService = {\n mapTransactionToSubset: vi.fn(),\n } as unknown as TransactionMapperService;\n const parserMock: TransactionParserService = {\n extractValue: vi.fn(),\n } as unknown as TransactionParserService;\n const getAppConfigMock = vi.fn();\n const web3CheckOptInMock = vi.fn();\n const parseTransactionMock = vi.fn();\n const buildContextsMock = vi.fn();\n const provideContextsMock = vi.fn();\n const signTransactionMock = vi.fn();\n function extractDependenciesMock() {\n return {\n getAppConfig: getAppConfigMock,\n web3CheckOptIn: web3CheckOptInMock,\n parseTransaction: parseTransactionMock,\n buildContexts: buildContextsMock,\n provideContexts: provideContextsMock,\n signTransaction: signTransactionMock,\n };\n }\n const apiMock = makeDeviceActionInternalApiMock();\n const defaultOptions = {\n domain: \"domain-name.eth\",\n };\n const defaultTransaction: Uint8Array = hexaStringToBuffer(\n Transaction.from({\n chainId: 1n,\n nonce: 0,\n data: \"0x\",\n }).unsignedSerialized,\n )!;\n const defaultSubset: TransactionSubset = {\n chainId: 1,\n data: \"0x\",\n selector: \"0x\",\n to: \"0x\",\n value: 0n,\n };\n\n function createAppConfig(\n version: string,\n web3ChecksEnabled: boolean,\n web3ChecksOptIn: boolean,\n ) {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn,\n version,\n };\n }\n\n function setupAppConfig(\n version: string,\n web3ChecksEnabled: boolean,\n web3ChecksOptIn: boolean,\n ) {\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n apiMock.getDeviceModel.mockReturnValueOnce({\n id: DeviceModelId.FLEX,\n } as unknown as TransportDeviceModel);\n getAppConfigMock.mockResolvedValue(\n CommandResultFactory({\n data: createAppConfig(version, web3ChecksEnabled, web3ChecksOptIn),\n }),\n );\n }\n\n const getStep = (s: Array<SignTransactionDAState>, index: number) => {\n if (s[index]?.status !== DeviceActionStatus.Pending) {\n throw new Error(\n `Step ${index} is not pending: ${JSON.stringify(s[index])}`,\n );\n }\n return s[index];\n };\n\n describe(\"Happy path\", () => {\n describe(\"should sign a transaction\", () => {\n const contexts: ContextWithSubContexts[] = [\n {\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n subcontextCallbacks: [],\n },\n {\n context: {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n subcontextCallbacks: [],\n },\n ];\n\n beforeEach(() => {\n vi.resetAllMocks();\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n // Mock the dependencies to return some sample data\n parseTransactionMock.mockResolvedValueOnce({\n subset: defaultSubset,\n type: TransactionType.EIP1559,\n });\n buildContextsMock.mockResolvedValueOnce({\n clearSignContexts: contexts,\n clearSigningType: ClearSigningType.EIP7730,\n });\n provideContextsMock.mockResolvedValueOnce(Just(void 0));\n signTransactionMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n\n observable = deviceAction._execute(apiMock).observable;\n });\n\n it(\"should open the app\", async () => {\n const { steps } = await executeUntilStep(0, observable);\n expect(getStep(steps, 0).intermediateValue.step).toBe(\n SignTransactionDAStep.OPEN_APP,\n );\n });\n\n it(\"should confirm open app\", async () => {\n const { steps } = await executeUntilStep(1, observable);\n expect(\n getStep(steps, 1).intermediateValue.requiredUserInteraction,\n ).toBe(UserInteractionRequired.ConfirmOpenApp);\n });\n\n it(\"should get app config\", async () => {\n const { steps } = await executeUntilStep(2, observable);\n expect(getStep(steps, 2).intermediateValue.step).toBe(\n SignTransactionDAStep.GET_APP_CONFIG,\n );\n });\n\n it(\"should prebuild context\", async () => {\n const { steps } = await executeUntilStep(3, observable);\n expect(getStep(steps, 3).intermediateValue.step).toBe(\n SignTransactionDAStep.PARSE_TRANSACTION,\n );\n expect(parseTransactionMock).toHaveBeenCalledTimes(1);\n expect(parseTransactionMock).toHaveBeenNthCalledWith(\n 1,\n expect.objectContaining({\n input: {\n mapper: mapperMock,\n transaction: defaultTransaction,\n },\n }),\n );\n });\n\n it(\"should build context\", async () => {\n const { steps } = await executeUntilStep(4, observable);\n expect(getStep(steps, 4).intermediateValue.step).toBe(\n SignTransactionDAStep.BUILD_CONTEXTS,\n );\n expect(buildContextsMock).toHaveBeenCalledTimes(1);\n expect(buildContextsMock).toHaveBeenNthCalledWith(\n 1,\n expect.objectContaining({\n input: {\n contextModule: contextModuleMock,\n parser: parserMock,\n mapper: mapperMock,\n options: defaultOptions,\n subset: defaultSubset,\n transaction: defaultTransaction,\n appConfig: createAppConfig(\"1.15.0\", false, false),\n derivationPath: \"44'/60'/0'/0/0\",\n deviceModelId: DeviceModelId.FLEX,\n },\n }),\n );\n });\n\n it(\"should provide context\", async () => {\n const { steps } = await executeUntilStep(5, observable);\n expect(getStep(steps, 5).intermediateValue.step).toBe(\n SignTransactionDAStep.PROVIDE_CONTEXTS,\n );\n expect(provideContextsMock).toHaveBeenCalledTimes(1);\n expect(provideContextsMock).toHaveBeenNthCalledWith(\n 1,\n expect.objectContaining({\n input: {\n contexts: contexts,\n serializedTransaction: defaultTransaction,\n derivationPath: \"44'/60'/0'/0/0\",\n },\n }),\n );\n });\n\n it(\"should sign transaction\", async () => {\n const { steps } = await executeUntilStep(6, observable);\n expect(getStep(steps, 6).intermediateValue.step).toBe(\n SignTransactionDAStep.SIGN_TRANSACTION,\n );\n expect(signTransactionMock).toHaveBeenCalledTimes(1);\n expect(signTransactionMock).toHaveBeenNthCalledWith(\n 1,\n expect.objectContaining({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n serializedTransaction: defaultTransaction,\n chainId: 1,\n transactionType: TransactionType.EIP1559,\n clearSigningType: ClearSigningType.EIP7730,\n },\n }),\n );\n });\n\n it(\"should return the signature\", async () => {\n const result = await lastValueFrom(observable);\n expect(result).toEqual({\n status: DeviceActionStatus.Completed,\n output: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n });\n });\n });\n\n describe(\"should skip open app\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: { ...defaultOptions, skipOpenApp: true },\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n parseTransactionMock.mockResolvedValueOnce({\n subset: defaultSubset,\n type: TransactionType.EIP1559,\n });\n buildContextsMock.mockResolvedValueOnce({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n provideContextsMock.mockResolvedValueOnce(Just(void 0));\n signTransactionMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n\n observable = deviceAction._execute(apiMock).observable;\n });\n\n it(\"should skip open app and get app config directly\", async () => {\n const { steps } = await executeUntilStep(0, observable);\n\n expect(getStep(steps, 0).intermediateValue.step).toBe(\n SignTransactionDAStep.GET_APP_CONFIG,\n );\n });\n });\n\n describe(\"should opt in to web3 checks\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n setupOpenAppDAMock();\n setupAppConfig(\"1.16.0\", false, false);\n\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n web3CheckOptInMock.mockResolvedValueOnce(\n CommandResultFactory({ data: { enabled: true } }),\n );\n\n observable = deviceAction._execute(apiMock).observable;\n });\n\n it(\"should opt in to web3 checks if app config is supported and not already enabled\", async () => {\n const { steps } = await executeUntilStep(4, observable);\n\n expect(getStep(steps, 3).intermediateValue.step).toBe(\n SignTransactionDAStep.WEB3_CHECKS_OPT_IN,\n );\n expect(web3CheckOptInMock).toHaveBeenCalledTimes(1);\n\n expect(getStep(steps, 4).intermediateValue.step).toBe(\n SignTransactionDAStep.WEB3_CHECKS_OPT_IN_RESULT,\n );\n // @ts-expect-error - result is not typed\n expect(getStep(steps, 4).intermediateValue.result).toBe(true);\n });\n });\n\n describe(\"should not opt in to web3 checks\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n setupOpenAppDAMock();\n\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n\n observable = deviceAction._execute(apiMock).observable;\n });\n\n it(\"should not opt in to web3 checks if app config is not supported\", async () => {\n setupAppConfig(\"1.15.0\", false, false);\n await executeUntilStep(3, observable);\n expect(web3CheckOptInMock).not.toHaveBeenCalled();\n });\n\n it(\"should not opt in to web3 checks if already enabled\", async () => {\n setupAppConfig(\"1.16.0\", true, false);\n await executeUntilStep(3, observable);\n expect(web3CheckOptInMock).not.toHaveBeenCalled();\n });\n\n it(\"should not opt in to web3 checks if already opted out\", async () => {\n setupAppConfig(\"1.16.0\", false, true);\n await executeUntilStep(3, observable);\n expect(web3CheckOptInMock).not.toHaveBeenCalled();\n });\n });\n });\n\n describe(\"Error cases\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should return an error if the open app throw an error\", async () => {\n // GIVEN\n setupOpenAppDAMock(new Error(\"Open app failed\"));\n setupAppConfig(\"1.15.0\", false, false);\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: new Error(\"Open app failed\"),\n });\n });\n\n it(\"should return an error if the get app config return an error\", async () => {\n // GIVEN\n setupOpenAppDAMock();\n getAppConfigMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: new InvalidStatusWordError(\"Get app config failed\"),\n }),\n );\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: new InvalidStatusWordError(\"Get app config failed\"),\n });\n });\n\n it(\"should return an error if the get app config throw an error\", async () => {\n // GIVEN\n setupOpenAppDAMock();\n getAppConfigMock.mockRejectedValueOnce(\n new Error(\"Get app config failed\"),\n );\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: new Error(\"Get app config failed\"),\n });\n });\n\n it(\"should ignore the web3checks result if the command fails\", async () => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.16.0\", false, false);\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n web3CheckOptInMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: new InvalidStatusWordError(\"web3 check opt in failed\"),\n }),\n );\n parseTransactionMock.mockResolvedValueOnce({\n subset: defaultSubset,\n type: TransactionType.EIP1559,\n });\n buildContextsMock.mockResolvedValueOnce({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n signTransactionMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Completed,\n output: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n });\n });\n\n it(\"should return an error if the parse transaction throw an error\", async () => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n parseTransactionMock.mockRejectedValueOnce(\n new Error(\"Parse transaction failed\"),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: new Error(\"Parse transaction failed\"),\n });\n });\n\n it(\"should blind sign if the build contexts fails\", async () => {\n // TODO: implement this test\n });\n\n it(\"should blind sign if the provide contexts fails\", async () => {\n // TODO: implement this test\n });\n\n it(\"should return an error if the sign transaction fails\", async () => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n parseTransactionMock.mockResolvedValueOnce({\n subset: defaultSubset,\n type: TransactionType.EIP1559,\n });\n buildContextsMock.mockResolvedValueOnce({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n provideContextsMock.mockResolvedValueOnce(Just(void 0));\n signTransactionMock.mockRejectedValueOnce(\n new Error(\"Sign transaction failed\"),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: new Error(\"Sign transaction failed\"),\n });\n });\n\n it(\"should return an error if the sign transaction return an error\", async () => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n parseTransactionMock.mockResolvedValueOnce({\n subset: defaultSubset,\n type: TransactionType.EIP1559,\n });\n buildContextsMock.mockResolvedValueOnce({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n provideContextsMock.mockResolvedValueOnce(Just(void 0));\n signTransactionMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: new InvalidStatusWordError(\"Sign transaction failed\"),\n }),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: new InvalidStatusWordError(\"Sign transaction failed\"),\n });\n });\n });\n});\n"],
5
- "mappings": "aACA,IAAAA,EAIO,oCACPC,EAWO,2CACPC,EAA4B,kBAC5BC,EAAqB,qBACrBC,EAA0C,gBAE1CC,EAKO,4DAEPC,EAAiC,uCACjCC,EAAgC,sCAChCC,EAAgD,6EAChDC,EAAmC,gFACnCC,EAAiC,uFAKjCC,EAA4C,yCAE5C,GAAG,KAAK,kCAAmC,MAAOC,IAGzC,CACL,GAFA,MAAMA,EAAiE,EAGvE,oBAAqB,GAAG,GAAG,KAAO,CAChC,iBAAkB,GAAG,GAAG,CAC1B,EAAE,CACJ,EACD,EAED,SAAS,8BAA+B,IAAM,CAC5C,IAAIC,EAOJ,MAAMC,EAAmC,CACvC,gBAAiB,GAAG,GAAG,EACvB,YAAa,GAAG,GAAG,EACnB,oBAAqB,GAAG,GAAG,EAC3B,cAAe,GAAG,GAAG,EACrB,iBAAkB,GAAG,GAAG,CAC1B,EACMC,EAAuC,CAC3C,uBAAwB,GAAG,GAAG,CAChC,EACMC,EAAuC,CAC3C,aAAc,GAAG,GAAG,CACtB,EACMC,EAAmB,GAAG,GAAG,EACzBC,EAAqB,GAAG,GAAG,EAC3BC,EAAuB,GAAG,GAAG,EAC7BC,EAAoB,GAAG,GAAG,EAC1BC,EAAsB,GAAG,GAAG,EAC5BC,EAAsB,GAAG,GAAG,EAClC,SAASC,GAA0B,CACjC,MAAO,CACL,aAAcN,EACd,eAAgBC,EAChB,iBAAkBC,EAClB,cAAeC,EACf,gBAAiBC,EACjB,gBAAiBC,CACnB,CACF,CACA,MAAME,KAAU,mCAAgC,EAC1CC,EAAiB,CACrB,OAAQ,iBACV,EACMC,KAAiC,sBACrC,cAAY,KAAK,CACf,QAAS,GACT,MAAO,EACP,KAAM,IACR,CAAC,EAAE,kBACL,EACMC,EAAmC,CACvC,QAAS,EACT,KAAM,KACN,SAAU,KACV,GAAI,KACJ,MAAO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M,yBAAyB,CACrC,EACAT,EAAawB,EAAa,SAASb,CAAO,EAAE,WAG5C,MAAMe,EAAS,QAAM,iBAAc1B,CAAU,EAG7C,OAAO0B,CAAM,EAAE,QAAQ,CACrB,OAAQ,qBAAmB,MAC3B,MAAO,IAAI,MAAM,yBAAyB,CAC5C,CAAC,CACH,CAAC,EAED,GAAG,iEAAkE,SAAY,IAC/E,sBAAmB,EACnBP,EAAe,SAAU,GAAO,EAAK,EACrC,MAAMK,EAAe,IAAI,8BAA4B,CACnD,MAAO,CACL,eAAgB,iBAChB,YAAaX,EACb,QAASD,EACT,cAAeX,EACf,OAAQC,EACR,OAAQC,CACV,CACF,CAAC,EACD,GAAG,MAAMqB,EAAc,qBAAqB,EAAE,gBAC5Cd,EAAwB,CAC1B,EACAJ,EAAqB,sBAAsB,CACzC,OAAQQ,EACR,KAAM,kBAAgB,OACxB,CAAC,EACDP,EAAkB,sBAAsB,CACtC,kBAAmB,CAAC,EACpB,0BAA2B,CAAC,EAC5B,iBAAkB,mBAAiB,KACrC,CAAC,EACDC,EAAoB,yBAAsB,QAAK,MAAM,CAAC,EACtDC,EAAoB,yBAClB,wBAAqB,CACnB,MAAO,IAAI,yBAAuB,yBAAyB,CAC7D,CAAC,CACH,EACAT,EAAawB,EAAa,SAASb,CAAO,EAAE,WAG5C,MAAMe,EAAS,QAAM,iBAAc1B,CAAU,EAG7C,OAAO0B,CAAM,EAAE,QAAQ,CACrB,OAAQ,qBAAmB,MAC3B,MAAO,IAAI,yBAAuB,yBAAyB,CAC7D,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["import_context_module", "import_device_management_kit", "import_ethers", "import_purify_ts", "import_rxjs", "import_SignTransactionDeviceActionTypes", "import_ClearSigningType", "import_TransactionType", "import_makeInternalApi", "import_setupOpenAppDAMock", "import_testDeviceActionUntilStep", "import_SignTransactionDeviceAction", "importOriginal", "observable", "contextModuleMock", "mapperMock", "parserMock", "getAppConfigMock", "web3CheckOptInMock", "parseTransactionMock", "buildContextsMock", "provideContextsMock", "signTransactionMock", "extractDependenciesMock", "apiMock", "defaultOptions", "defaultTransaction", "defaultSubset", "createAppConfig", "version", "web3ChecksEnabled", "web3ChecksOptIn", "setupAppConfig", "getStep", "s", "index", "contexts", "deviceAction", "steps", "result"]
4
+ "sourcesContent": ["/* eslint @typescript-eslint/consistent-type-imports: 0 */\nimport {\n ClearSignContextType,\n type ContextModule,\n TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n CommandResultFactory,\n DeviceActionState,\n DeviceActionStatus,\n DeviceModelId,\n DeviceSessionStateType,\n DeviceStatus,\n hexaStringToBuffer,\n InvalidStatusWordError,\n TransportDeviceModel,\n UserInteractionRequired,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"ethers\";\nimport { Just } from \"purify-ts\";\nimport { lastValueFrom, Observable } from \"rxjs\";\n\nimport {\n SignTransactionDAError,\n SignTransactionDAIntermediateValue,\n type SignTransactionDAState,\n SignTransactionDAStep,\n} from \"@api/app-binder/SignTransactionDeviceActionTypes\";\nimport { Signature } from \"@api/index\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { TransactionType } from \"@api/model/TransactionType\";\nimport { makeDeviceActionInternalApiMock } from \"@internal/app-binder/device-action/__test-utils__/makeInternalApi\";\nimport { setupOpenAppDAMock } from \"@internal/app-binder/device-action/__test-utils__/setupOpenAppDAMock\";\nimport { executeUntilStep } from \"@internal/app-binder/device-action/__test-utils__/testDeviceActionUntilStep\";\nimport { ContextWithSubContexts } from \"@internal/app-binder/task/BuildFullContextsTask\";\nimport { type TransactionMapperService } from \"@internal/transaction/service/mapper/TransactionMapperService\";\nimport { type TransactionParserService } from \"@internal/transaction/service/parser/TransactionParserService\";\n\nimport { SignTransactionDeviceAction } from \"./SignTransactionDeviceAction\";\n\nvi.mock(\"@ledgerhq/device-management-kit\", async (importOriginal) => {\n const original =\n await importOriginal<typeof import(\"@ledgerhq/device-management-kit\")>();\n return {\n ...original,\n OpenAppDeviceAction: vi.fn(() => ({\n makeStateMachine: vi.fn(),\n })),\n };\n});\n\ndescribe(\"SignTransactionDeviceAction\", () => {\n let observable: Observable<\n DeviceActionState<\n Signature,\n SignTransactionDAError,\n SignTransactionDAIntermediateValue\n >\n >;\n const contextModuleMock: ContextModule = {\n getFieldContext: vi.fn(),\n getContexts: vi.fn(),\n getTypedDataFilters: vi.fn(),\n getWeb3Checks: vi.fn(),\n getSolanaContext: vi.fn(),\n };\n const mapperMock: TransactionMapperService = {\n mapTransactionToSubset: vi.fn(),\n } as unknown as TransactionMapperService;\n const parserMock: TransactionParserService = {\n extractValue: vi.fn(),\n } as unknown as TransactionParserService;\n const getAppConfigMock = vi.fn();\n const web3CheckOptInMock = vi.fn();\n const parseTransactionMock = vi.fn();\n const buildContextsMock = vi.fn();\n const provideContextsMock = vi.fn();\n const signTransactionMock = vi.fn();\n function extractDependenciesMock() {\n return {\n getAppConfig: getAppConfigMock,\n web3CheckOptIn: web3CheckOptInMock,\n parseTransaction: parseTransactionMock,\n buildContexts: buildContextsMock,\n provideContexts: provideContextsMock,\n signTransaction: signTransactionMock,\n };\n }\n const apiMock = makeDeviceActionInternalApiMock();\n const defaultOptions = {\n domain: \"domain-name.eth\",\n };\n const defaultTransaction: Uint8Array = hexaStringToBuffer(\n Transaction.from({\n chainId: 1n,\n nonce: 0,\n data: \"0x\",\n }).unsignedSerialized,\n )!;\n const defaultSubset: TransactionSubset = {\n chainId: 1,\n data: \"0x\",\n selector: \"0x\",\n to: \"0x\",\n value: 0n,\n };\n\n function createAppConfig(\n version: string,\n web3ChecksEnabled: boolean,\n web3ChecksOptIn: boolean,\n ) {\n return {\n blindSigningEnabled: false,\n web3ChecksEnabled,\n web3ChecksOptIn,\n version,\n };\n }\n\n function setupAppConfig(\n version: string,\n web3ChecksEnabled: boolean,\n web3ChecksOptIn: boolean,\n ) {\n apiMock.getDeviceSessionState.mockReturnValueOnce({\n sessionStateType: DeviceSessionStateType.ReadyWithoutSecureChannel,\n deviceStatus: DeviceStatus.CONNECTED,\n installedApps: [],\n currentApp: { name: \"Ethereum\", version },\n deviceModelId: DeviceModelId.FLEX,\n isSecureConnectionAllowed: false,\n });\n apiMock.getDeviceModel.mockReturnValueOnce({\n id: DeviceModelId.FLEX,\n } as unknown as TransportDeviceModel);\n getAppConfigMock.mockResolvedValue(\n CommandResultFactory({\n data: createAppConfig(version, web3ChecksEnabled, web3ChecksOptIn),\n }),\n );\n }\n\n const getStep = (s: Array<SignTransactionDAState>, index: number) => {\n if (s[index]?.status !== DeviceActionStatus.Pending) {\n throw new Error(\n `Step ${index} is not pending: ${JSON.stringify(s[index])}`,\n );\n }\n return s[index];\n };\n\n describe(\"Happy path\", () => {\n describe(\"should sign a transaction\", () => {\n const contexts: ContextWithSubContexts[] = [\n {\n context: {\n type: ClearSignContextType.TRANSACTION_INFO,\n payload: \"payload-1\",\n },\n subcontextCallbacks: [],\n },\n {\n context: {\n type: ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n payload: \"payload-2\",\n },\n subcontextCallbacks: [],\n },\n ];\n\n beforeEach(() => {\n vi.resetAllMocks();\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n // Mock the dependencies to return some sample data\n parseTransactionMock.mockResolvedValueOnce({\n subset: defaultSubset,\n type: TransactionType.EIP1559,\n });\n buildContextsMock.mockResolvedValueOnce({\n clearSignContexts: contexts,\n clearSigningType: ClearSigningType.EIP7730,\n });\n provideContextsMock.mockResolvedValueOnce(Just(void 0));\n signTransactionMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n\n observable = deviceAction._execute(apiMock).observable;\n });\n\n it(\"should open the app\", async () => {\n const { steps } = await executeUntilStep(0, observable);\n expect(getStep(steps, 0).intermediateValue.step).toBe(\n SignTransactionDAStep.OPEN_APP,\n );\n });\n\n it(\"should confirm open app\", async () => {\n const { steps } = await executeUntilStep(1, observable);\n expect(\n getStep(steps, 1).intermediateValue.requiredUserInteraction,\n ).toBe(UserInteractionRequired.ConfirmOpenApp);\n });\n\n it(\"should get app config\", async () => {\n const { steps } = await executeUntilStep(2, observable);\n expect(getStep(steps, 2).intermediateValue.step).toBe(\n SignTransactionDAStep.GET_APP_CONFIG,\n );\n });\n\n it(\"should prebuild context\", async () => {\n const { steps } = await executeUntilStep(3, observable);\n expect(getStep(steps, 3).intermediateValue.step).toBe(\n SignTransactionDAStep.PARSE_TRANSACTION,\n );\n expect(parseTransactionMock).toHaveBeenCalledTimes(1);\n expect(parseTransactionMock).toHaveBeenNthCalledWith(\n 1,\n expect.objectContaining({\n input: {\n mapper: mapperMock,\n transaction: defaultTransaction,\n },\n }),\n );\n });\n\n it(\"should build context\", async () => {\n const { steps } = await executeUntilStep(4, observable);\n expect(getStep(steps, 4).intermediateValue.step).toBe(\n SignTransactionDAStep.BUILD_CONTEXTS,\n );\n expect(buildContextsMock).toHaveBeenCalledTimes(1);\n expect(buildContextsMock).toHaveBeenNthCalledWith(\n 1,\n expect.objectContaining({\n input: {\n contextModule: contextModuleMock,\n parser: parserMock,\n mapper: mapperMock,\n options: defaultOptions,\n subset: defaultSubset,\n transaction: defaultTransaction,\n appConfig: createAppConfig(\"1.15.0\", false, false),\n derivationPath: \"44'/60'/0'/0/0\",\n deviceModelId: DeviceModelId.FLEX,\n },\n }),\n );\n });\n\n it(\"should provide context\", async () => {\n const { steps } = await executeUntilStep(5, observable);\n expect(getStep(steps, 5).intermediateValue.step).toBe(\n SignTransactionDAStep.PROVIDE_CONTEXTS,\n );\n expect(provideContextsMock).toHaveBeenCalledTimes(1);\n expect(provideContextsMock).toHaveBeenNthCalledWith(\n 1,\n expect.objectContaining({\n input: {\n contexts: contexts,\n serializedTransaction: defaultTransaction,\n derivationPath: \"44'/60'/0'/0/0\",\n },\n }),\n );\n });\n\n it(\"should sign transaction\", async () => {\n const { steps } = await executeUntilStep(6, observable);\n expect(getStep(steps, 6).intermediateValue.step).toBe(\n SignTransactionDAStep.SIGN_TRANSACTION,\n );\n expect(signTransactionMock).toHaveBeenCalledTimes(1);\n expect(signTransactionMock).toHaveBeenNthCalledWith(\n 1,\n expect.objectContaining({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n serializedTransaction: defaultTransaction,\n chainId: 1,\n transactionType: TransactionType.EIP1559,\n clearSigningType: ClearSigningType.EIP7730,\n },\n }),\n );\n });\n\n it(\"should return the signature\", async () => {\n const result = await lastValueFrom(observable);\n expect(result).toEqual({\n status: DeviceActionStatus.Completed,\n output: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n });\n });\n });\n\n describe(\"should skip open app\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: { ...defaultOptions, skipOpenApp: true },\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n parseTransactionMock.mockResolvedValueOnce({\n subset: defaultSubset,\n type: TransactionType.EIP1559,\n });\n buildContextsMock.mockResolvedValueOnce({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n provideContextsMock.mockResolvedValueOnce(Just(void 0));\n signTransactionMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n\n observable = deviceAction._execute(apiMock).observable;\n });\n\n it(\"should skip open app and get app config directly\", async () => {\n const { steps } = await executeUntilStep(0, observable);\n\n expect(getStep(steps, 0).intermediateValue.step).toBe(\n SignTransactionDAStep.GET_APP_CONFIG,\n );\n });\n });\n\n describe(\"should opt in to web3 checks\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n setupOpenAppDAMock();\n setupAppConfig(\"1.16.0\", false, false);\n\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n web3CheckOptInMock.mockResolvedValueOnce(\n CommandResultFactory({ data: { enabled: true } }),\n );\n\n observable = deviceAction._execute(apiMock).observable;\n });\n\n it(\"should opt in to web3 checks if app config is supported and not already enabled\", async () => {\n const { steps } = await executeUntilStep(4, observable);\n\n expect(getStep(steps, 3).intermediateValue.step).toBe(\n SignTransactionDAStep.WEB3_CHECKS_OPT_IN,\n );\n expect(web3CheckOptInMock).toHaveBeenCalledTimes(1);\n\n expect(getStep(steps, 4).intermediateValue.step).toBe(\n SignTransactionDAStep.WEB3_CHECKS_OPT_IN_RESULT,\n );\n // @ts-expect-error - result is not typed\n expect(getStep(steps, 4).intermediateValue.result).toBe(true);\n });\n });\n\n describe(\"should not opt in to web3 checks\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n setupOpenAppDAMock();\n\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n\n observable = deviceAction._execute(apiMock).observable;\n });\n\n it(\"should not opt in to web3 checks if app config is not supported\", async () => {\n setupAppConfig(\"1.15.0\", false, false);\n await executeUntilStep(3, observable);\n expect(web3CheckOptInMock).not.toHaveBeenCalled();\n });\n\n it(\"should not opt in to web3 checks if already enabled\", async () => {\n setupAppConfig(\"1.16.0\", true, false);\n await executeUntilStep(3, observable);\n expect(web3CheckOptInMock).not.toHaveBeenCalled();\n });\n\n it(\"should not opt in to web3 checks if already opted out\", async () => {\n setupAppConfig(\"1.16.0\", false, true);\n await executeUntilStep(3, observable);\n expect(web3CheckOptInMock).not.toHaveBeenCalled();\n });\n });\n });\n\n describe(\"Error cases\", () => {\n beforeEach(() => {\n vi.resetAllMocks();\n });\n\n it(\"should return an error if the open app throw an error\", async () => {\n // GIVEN\n setupOpenAppDAMock(new Error(\"Open app failed\"));\n setupAppConfig(\"1.15.0\", false, false);\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: new Error(\"Open app failed\"),\n });\n });\n\n it(\"should return an error if the get app config return an error\", async () => {\n // GIVEN\n setupOpenAppDAMock();\n getAppConfigMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: new InvalidStatusWordError(\"Get app config failed\"),\n }),\n );\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: new InvalidStatusWordError(\"Get app config failed\"),\n });\n });\n\n it(\"should return an error if the get app config throw an error\", async () => {\n // GIVEN\n setupOpenAppDAMock();\n getAppConfigMock.mockRejectedValueOnce(\n new Error(\"Get app config failed\"),\n );\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: new Error(\"Get app config failed\"),\n });\n });\n\n it(\"should ignore the web3checks result if the command fails\", async () => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.16.0\", false, false);\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n web3CheckOptInMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: new InvalidStatusWordError(\"web3 check opt in failed\"),\n }),\n );\n parseTransactionMock.mockResolvedValueOnce({\n subset: defaultSubset,\n type: TransactionType.EIP1559,\n });\n buildContextsMock.mockResolvedValueOnce({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n signTransactionMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Completed,\n output: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad788\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n });\n });\n\n it(\"should return an error if the parse transaction throw an error\", async () => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n parseTransactionMock.mockRejectedValueOnce(\n new Error(\"Parse transaction failed\"),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: new Error(\"Parse transaction failed\"),\n });\n });\n\n it(\"should blind sign if the first sign transaction fails and the second sign transaction succeeds\", async () => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n parseTransactionMock.mockResolvedValueOnce({\n subset: defaultSubset,\n type: TransactionType.EIP1559,\n });\n buildContextsMock.mockResolvedValueOnce({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n provideContextsMock.mockResolvedValueOnce(Just(void 0));\n signTransactionMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: new InvalidStatusWordError(\"Sign transaction failed\"),\n }),\n );\n signTransactionMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad789\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Completed,\n output: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad789\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n });\n });\n\n it(\"should blind sign if the first sign transaction throws an error and the second sign transaction succeeds\", async () => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n parseTransactionMock.mockResolvedValueOnce({\n subset: defaultSubset,\n type: TransactionType.EIP1559,\n });\n buildContextsMock.mockResolvedValueOnce({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.EIP7730,\n });\n provideContextsMock.mockResolvedValueOnce(Just(void 0));\n signTransactionMock.mockRejectedValueOnce(\n new Error(\"Sign transaction failed\"),\n );\n signTransactionMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad789\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Completed,\n output: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad789\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n });\n expect(signTransactionMock).toHaveBeenCalledTimes(2);\n expect(signTransactionMock).toHaveBeenNthCalledWith(\n 1,\n expect.objectContaining({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n serializedTransaction: defaultTransaction,\n chainId: 1,\n transactionType: TransactionType.EIP1559,\n clearSigningType: ClearSigningType.EIP7730,\n },\n }),\n );\n expect(signTransactionMock).toHaveBeenNthCalledWith(\n 2,\n expect.objectContaining({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n serializedTransaction: defaultTransaction,\n chainId: 1,\n transactionType: TransactionType.EIP1559,\n clearSigningType: ClearSigningType.BASIC, // fallback to basic\n },\n }),\n );\n });\n\n it(\"should return an error if the sign transaction return two times an error\", async () => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n parseTransactionMock.mockResolvedValueOnce({\n subset: defaultSubset,\n type: TransactionType.EIP1559,\n });\n buildContextsMock.mockResolvedValueOnce({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n provideContextsMock.mockResolvedValueOnce(Just(void 0));\n signTransactionMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: new InvalidStatusWordError(\"Sign transaction failed\"),\n }),\n );\n signTransactionMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: new InvalidStatusWordError(\"Blind sign transaction failed\"),\n }),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: new InvalidStatusWordError(\"Blind sign transaction failed\"),\n });\n });\n\n it(\"should return an error if the blind sign transaction fallback throws an error\", async () => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n parseTransactionMock.mockResolvedValueOnce({\n subset: defaultSubset,\n type: TransactionType.EIP1559,\n });\n buildContextsMock.mockResolvedValueOnce({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n provideContextsMock.mockResolvedValueOnce(Just(void 0));\n signTransactionMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: new InvalidStatusWordError(\"Sign transaction failed\"),\n }),\n );\n signTransactionMock.mockRejectedValueOnce(\n new Error(\"Blind sign transaction fallback failed\"),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: new Error(\"Blind sign transaction fallback failed\"),\n });\n });\n\n it(\"should return an error without trying blind sign fallback when user refuses transaction (error code 6985)\", async () => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n parseTransactionMock.mockResolvedValueOnce({\n subset: defaultSubset,\n type: TransactionType.EIP1559,\n });\n buildContextsMock.mockResolvedValueOnce({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n });\n provideContextsMock.mockResolvedValueOnce(Just(void 0));\n\n // Create an error with the user refusal error code\n const userRefusalError = new InvalidStatusWordError(\n \"User refused transaction\",\n );\n (\n userRefusalError as InvalidStatusWordError & { errorCode: string }\n ).errorCode = \"6985\";\n\n signTransactionMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: userRefusalError,\n }),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Error,\n error: userRefusalError,\n });\n // Verify that signTransaction was only called once (no blind sign fallback attempt)\n expect(signTransactionMock).toHaveBeenCalledTimes(1);\n });\n\n it(\"should try blind sign fallback when error is not user refusal (different error code)\", async () => {\n setupOpenAppDAMock();\n setupAppConfig(\"1.15.0\", false, false);\n const deviceAction = new SignTransactionDeviceAction({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n transaction: defaultTransaction,\n options: defaultOptions,\n contextModule: contextModuleMock,\n mapper: mapperMock,\n parser: parserMock,\n },\n });\n vi.spyOn(deviceAction, \"extractDependencies\").mockReturnValue(\n extractDependenciesMock(),\n );\n parseTransactionMock.mockResolvedValueOnce({\n subset: defaultSubset,\n type: TransactionType.EIP1559,\n });\n buildContextsMock.mockResolvedValueOnce({\n clearSignContexts: [],\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.EIP7730,\n });\n provideContextsMock.mockResolvedValueOnce(Just(void 0));\n\n // Create an error with a different error code (not user refusal)\n const otherError = new InvalidStatusWordError(\"Some other error\");\n (otherError as InvalidStatusWordError & { errorCode: string }).errorCode =\n \"6A80\";\n\n signTransactionMock.mockResolvedValueOnce(\n CommandResultFactory({\n error: otherError,\n }),\n );\n signTransactionMock.mockResolvedValueOnce(\n CommandResultFactory({\n data: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad789\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n }),\n );\n observable = deviceAction._execute(apiMock).observable;\n\n // WHEN\n const result = await lastValueFrom(observable);\n\n // THEN\n expect(result).toEqual({\n status: DeviceActionStatus.Completed,\n output: {\n v: 0x1c,\n r: \"0x8a540510e13b0f2b11a451275716d29e08caad07e89a1c84964782fb5e1ad789\",\n s: \"0x64a0de235b270fbe81e8e40688f4a9f9ad9d283d690552c9331d7773ceafa513\",\n },\n });\n // Verify that signTransaction was called twice (first attempt + blind sign fallback)\n expect(signTransactionMock).toHaveBeenCalledTimes(2);\n expect(signTransactionMock).toHaveBeenNthCalledWith(\n 1,\n expect.objectContaining({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n serializedTransaction: defaultTransaction,\n chainId: 1,\n transactionType: TransactionType.EIP1559,\n clearSigningType: ClearSigningType.EIP7730,\n },\n }),\n );\n expect(signTransactionMock).toHaveBeenNthCalledWith(\n 2,\n expect.objectContaining({\n input: {\n derivationPath: \"44'/60'/0'/0/0\",\n serializedTransaction: defaultTransaction,\n chainId: 1,\n transactionType: TransactionType.EIP1559,\n clearSigningType: ClearSigningType.BASIC, // fallback to basic\n },\n }),\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ChB,sBAAuBI,EACvB,QAAS,EACT,gBAAiB,kBAAgB,QACjC,iBAAkB,mBAAiB,OACrC,CACF,CAAC,CACH,EACA,OAAOJ,CAAmB,EAAE,wBAC1B,EACA,OAAO,iBAAiB,CACtB,MAAO,CACL,eAAgB,iBAChB,sBAAuBI,EACvB,QAAS,EACT,gBAAiB,kBAAgB,QACjC,iBAAkB,mBAAiB,KACrC,CACF,CAAC,CACH,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_context_module", "import_device_management_kit", "import_ethers", "import_purify_ts", "import_rxjs", "import_SignTransactionDeviceActionTypes", "import_ClearSigningType", "import_TransactionType", "import_makeInternalApi", "import_setupOpenAppDAMock", "import_testDeviceActionUntilStep", "import_SignTransactionDeviceAction", "importOriginal", "observable", "contextModuleMock", "mapperMock", "parserMock", "getAppConfigMock", "web3CheckOptInMock", "parseTransactionMock", "buildContextsMock", "provideContextsMock", "signTransactionMock", "extractDependenciesMock", "apiMock", "defaultOptions", "defaultTransaction", "defaultSubset", "createAppConfig", "version", "web3ChecksEnabled", "web3ChecksOptIn", "setupAppConfig", "getStep", "s", "index", "contexts", "deviceAction", "steps", "result", "userRefusalError", "otherError"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var y=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var M=(s,e)=>{for(var i in e)y(s,i,{get:e[i],enumerable:!0})},k=(s,e,i,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of R(e))!v.call(s,o)&&o!==i&&y(s,o,{get:()=>e[o],enumerable:!(a=_(e,o))||a.enumerable});return s};var b=s=>k(y({},"__esModule",{value:!0}),s);var B={};M(B,{BuildBaseContexts:()=>w});module.exports=b(B);var n=require("@ledgerhq/context-module"),p=require("@ledgerhq/device-management-kit"),u=require("../../../api/model/ClearSigningType"),I=require("../../app-binder/command/GetChallengeCommand"),h=require("../../app-binder/task/GetWeb3CheckTask"),A=require("../../shared/utils/ApplicationChecker");class w{constructor(e,i,a=(o,d)=>new h.GetWeb3CheckTask(o,d)){this._api=e;this._args=i;this.getWeb3ChecksFactory=a}async run(){const{contextModule:e,options:i,appConfig:a,derivationPath:o,transaction:d,subset:x}=this._args,S=this._api.getDeviceSessionState();let l=[],f=[],m=u.ClearSigningType.BASIC,c=null;d&&a.web3ChecksEnabled&&(c=(await this.getWeb3ChecksFactory(this._api,{contextModule:e,derivationPath:o,subset:x,transaction:d}).run()).web3Check);let T;if(S.deviceModelId!==p.DeviceModelId.NANO_S){const t=await this._api.sendCommand(new I.GetChallengeCommand);(0,p.isSuccessCommandResult)(t)&&(T=t.data.challenge)}const N=await e.getContexts({challenge:T,domain:i.domain,deviceModelId:S.deviceModelId,...x}),C=N.filter(t=>t.type!==n.ClearSignContextType.ERROR&&t.type!==n.ClearSignContextType.ENUM),E=N.filter(t=>t.type===n.ClearSignContextType.ENUM),g=C.find(t=>t.type===n.ClearSignContextType.TRANSACTION_INFO);if(!this.supportsGenericParser(S,a)||g===void 0)l=C.filter(t=>t.type!==n.ClearSignContextType.TRANSACTION_INFO&&t.type!==n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION),c&&(l=[c,...l]);else if(g.certificate){const t=C.filter(r=>r.type===n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION),O=C.filter(r=>r.type===n.ClearSignContextType.PROXY_DELEGATE_CALL);l=[...C.filter(r=>r.type===n.ClearSignContextType.DYNAMIC_NETWORK||r.type===n.ClearSignContextType.DYNAMIC_NETWORK_ICON),...O,g,...t,...c?[c]:[]],f=[...E],m=u.ClearSigningType.EIP7730}return{clearSignContexts:l,clearSignContextsOptional:f,clearSigningType:m}}supportsGenericParser(e,i){return new A.ApplicationChecker(e,i).withMinVersionExclusive("1.14.0").excludeDeviceModel(p.DeviceModelId.NANO_S).check()}}0&&(module.exports={BuildBaseContexts});
1
+ "use strict";var d=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var h=(r,t)=>{for(var n in t)d(r,n,{get:t[n],enumerable:!0})},y=(r,t,n,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of I(t))!E.call(r,s)&&s!==n&&d(r,s,{get:()=>t[s],enumerable:!(a=_(t,s))||a.enumerable});return r};var R=r=>y(d({},"__esModule",{value:!0}),r);var A={};h(A,{BuildBaseContexts:()=>O});module.exports=R(A);var e=require("@ledgerhq/context-module"),c=require("@ledgerhq/device-management-kit"),g=require("../../../api/model/ClearSigningType"),N=require("../../app-binder/command/GetChallengeCommand"),x=require("../../app-binder/task/GetWeb3CheckTask"),T=require("../../shared/utils/ApplicationChecker");class O{constructor(t,n,a=(s,o)=>new x.GetWeb3CheckTask(s,o)){this._api=t;this._args=n;this.getWeb3ChecksFactory=a}async run(){const{contextModule:t,options:n,appConfig:a,derivationPath:s,transaction:o,subset:S}=this._args,C=this._api.getDeviceSessionState();let p;if(C.deviceModelId!==c.DeviceModelId.NANO_S){const i=await this._api.sendCommand(new N.GetChallengeCommand);(0,c.isSuccessCommandResult)(i)&&(p=i.data.challenge)}const u=await t.getContexts({challenge:p,domain:n.domain,deviceModelId:C.deviceModelId,...S});if(o&&a.web3ChecksEnabled){const i=(await this.getWeb3ChecksFactory(this._api,{contextModule:t,derivationPath:s,subset:S,transaction:o}).run()).web3Check;i&&u.unshift(i)}const l=u.filter(i=>i.type!==e.ClearSignContextType.ERROR);return this._supportsGenericParser(C,a)&&this._hasValidTransactionInfo(l)?this._getERC7730Contexts(l):this._getBasicContexts(l)}_getERC7730Contexts(t){const n=t.filter(s=>this._isContextNeededForERC7730ClearSigning(s)).sort((s,o)=>this._getContextPriority(s)-this._getContextPriority(o)),a=t.filter(s=>s.type===e.ClearSignContextType.ENUM);return{clearSignContexts:n,clearSignContextsOptional:a,clearSigningType:g.ClearSigningType.EIP7730}}_getBasicContexts(t){return{clearSignContexts:t.filter(a=>this._isContextNeededForBasicClearSigning(a)).sort((a,s)=>this._getContextPriority(a)-this._getContextPriority(s)),clearSignContextsOptional:[],clearSigningType:g.ClearSigningType.BASIC}}_isContextNeededForBasicClearSigning({type:t}){switch(t){case e.ClearSignContextType.WEB3_CHECK:case e.ClearSignContextType.PLUGIN:case e.ClearSignContextType.EXTERNAL_PLUGIN:case e.ClearSignContextType.DYNAMIC_NETWORK:case e.ClearSignContextType.DYNAMIC_NETWORK_ICON:case e.ClearSignContextType.TRUSTED_NAME:case e.ClearSignContextType.TOKEN:case e.ClearSignContextType.NFT:return!0;case e.ClearSignContextType.TRANSACTION_INFO:case e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:case e.ClearSignContextType.ENUM:case e.ClearSignContextType.PROXY_INFO:return!1;default:{const n=t;throw new Error(`Unhandled context type ${String(n)}`)}}}_isContextNeededForERC7730ClearSigning({type:t}){switch(t){case e.ClearSignContextType.TRANSACTION_INFO:case e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:case e.ClearSignContextType.PROXY_INFO:case e.ClearSignContextType.WEB3_CHECK:case e.ClearSignContextType.DYNAMIC_NETWORK:case e.ClearSignContextType.DYNAMIC_NETWORK_ICON:return!0;case e.ClearSignContextType.ENUM:case e.ClearSignContextType.TRUSTED_NAME:case e.ClearSignContextType.TOKEN:case e.ClearSignContextType.NFT:case e.ClearSignContextType.PLUGIN:case e.ClearSignContextType.EXTERNAL_PLUGIN:return!1;default:{const n=t;throw new Error(`Unhandled context type ${String(n)}`)}}}_hasValidTransactionInfo(t){return t.find(n=>n.type===e.ClearSignContextType.TRANSACTION_INFO)?.certificate!==void 0}_supportsGenericParser(t,n){return new T.ApplicationChecker(t,n).withMinVersionExclusive("1.14.0").excludeDeviceModel(c.DeviceModelId.NANO_S).check()}_getContextPriority({type:t}){switch(t){case e.ClearSignContextType.WEB3_CHECK:return 10;case e.ClearSignContextType.DYNAMIC_NETWORK:case e.ClearSignContextType.DYNAMIC_NETWORK_ICON:case e.ClearSignContextType.PROXY_INFO:return 30;case e.ClearSignContextType.TRANSACTION_INFO:return 50;case e.ClearSignContextType.PLUGIN:case e.ClearSignContextType.EXTERNAL_PLUGIN:case e.ClearSignContextType.TOKEN:case e.ClearSignContextType.NFT:case e.ClearSignContextType.TRUSTED_NAME:case e.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:case e.ClearSignContextType.ENUM:return 70;default:{const n=t;throw new Error(`Unhandled context type for priority: ${String(n)}`)}}}}0&&(module.exports={BuildBaseContexts});
2
2
  //# sourceMappingURL=BuildBaseContexts.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/app-binder/task/BuildBaseContexts.ts"],
4
- "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n type ClearSignContextSuccessType,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n type DeviceSessionState,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport {\n GetWeb3CheckTask,\n type GetWeb3CheckTaskArgs,\n} from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { ApplicationChecker } from \"@internal/shared/utils/ApplicationChecker\";\n\nexport type BuildBaseContextsResult = {\n readonly clearSignContexts: ClearSignContextSuccess[];\n readonly clearSignContextsOptional: ClearSignContextSuccess[];\n readonly clearSigningType: ClearSigningType;\n};\n\nexport type BuildBaseContextsArgs = {\n readonly contextModule: ContextModule;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly derivationPath: string;\n readonly subset: TransactionSubset;\n readonly transaction?: Uint8Array;\n};\n\n/**\n * Builds the base contexts for a transaction\n * @param api - The internal API\n * @param args - The arguments for the build\n * @param getWeb3ChecksFactory - The factory for the web3 checks\n *\n * returns the base contexts for a transaction, without subcontexts or nested call data contexts\n */\nexport class BuildBaseContexts {\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: BuildBaseContextsArgs,\n private readonly getWeb3ChecksFactory = (\n api: InternalApi,\n args: GetWeb3CheckTaskArgs,\n ) => new GetWeb3CheckTask(api, args),\n ) {}\n\n async run(): Promise<BuildBaseContextsResult> {\n const {\n contextModule,\n options,\n appConfig,\n derivationPath,\n transaction,\n subset,\n } = this._args;\n const deviceState = this._api.getDeviceSessionState();\n let filteredContexts: ClearSignContextSuccess[] = [];\n let filteredContextOptional: ClearSignContextSuccess[] = [];\n let clearSigningType: ClearSigningType = ClearSigningType.BASIC;\n let web3Check: ClearSignContextSuccess<ClearSignContextType.WEB3_CHECK> | null =\n null;\n\n // Run the web3checks if needed\n if (transaction) {\n if (appConfig.web3ChecksEnabled) {\n web3Check = (\n await this.getWeb3ChecksFactory(this._api, {\n contextModule,\n derivationPath,\n subset,\n transaction,\n }).run()\n ).web3Check;\n }\n }\n\n // Get challenge (not supported on Nano S)\n let challenge: string | undefined = undefined;\n if (deviceState.deviceModelId !== DeviceModelId.NANO_S) {\n const challengeRes = await this._api.sendCommand(\n new GetChallengeCommand(),\n );\n if (isSuccessCommandResult(challengeRes)) {\n challenge = challengeRes.data.challenge;\n }\n }\n\n // Get the clear sign contexts\n const clearSignContexts: ClearSignContext[] =\n await contextModule.getContexts({\n challenge: challenge,\n domain: options.domain,\n deviceModelId: deviceState.deviceModelId,\n ...subset,\n });\n\n // NOTE: we need to filter out the ENUM and ERROR types\n // ENUM are handled differently\n // ERROR are not handled at all for now\n const clearSignContextsSuccess: ClearSignContextSuccess<\n Exclude<ClearSignContextSuccessType, ClearSignContextType.ENUM>\n >[] = clearSignContexts.filter(\n (context) =>\n context.type !== ClearSignContextType.ERROR &&\n context.type !== ClearSignContextType.ENUM,\n );\n\n // Retrieve all ENUM contexts\n const transactionEnums: ClearSignContextSuccess<ClearSignContextType.ENUM>[] =\n clearSignContexts.filter(\n (context) => context.type === ClearSignContextType.ENUM,\n );\n\n const transactionInfo = clearSignContextsSuccess.find(\n (ctx) => ctx.type === ClearSignContextType.TRANSACTION_INFO,\n );\n\n // If the device does not support the generic parser,\n // we need to filter out the transaction info and transaction field description\n // as they are not supported by the device\n if (\n !this.supportsGenericParser(deviceState, appConfig) ||\n transactionInfo === undefined\n ) {\n filteredContexts = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type !== ClearSignContextType.TRANSACTION_INFO &&\n ctx.type !== ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n\n // If the device supports the web3 check, we need to add it to the list of contexts\n if (web3Check) {\n filteredContexts = [web3Check, ...filteredContexts];\n }\n } else if (transactionInfo.certificate) {\n const transactionFields = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type === ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,\n );\n const proxyContexts = clearSignContextsSuccess.filter(\n (ctx) => ctx.type === ClearSignContextType.PROXY_DELEGATE_CALL,\n );\n const dynamicNetworkContexts = clearSignContextsSuccess.filter(\n (ctx) =>\n ctx.type === ClearSignContextType.DYNAMIC_NETWORK ||\n ctx.type === ClearSignContextType.DYNAMIC_NETWORK_ICON,\n );\n\n filteredContexts = [\n ...dynamicNetworkContexts,\n ...proxyContexts,\n transactionInfo,\n ...transactionFields,\n ...(web3Check ? [web3Check] : []),\n ];\n filteredContextOptional = [...transactionEnums];\n clearSigningType = ClearSigningType.EIP7730;\n }\n\n return {\n clearSignContexts: filteredContexts,\n clearSignContextsOptional: filteredContextOptional,\n clearSigningType,\n };\n }\n\n private supportsGenericParser(\n deviceState: DeviceSessionState,\n appConfig: GetConfigCommandResponse,\n ): boolean {\n return new ApplicationChecker(deviceState, appConfig)\n .withMinVersionExclusive(\"1.14.0\")\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n }\n}\n"],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,KAAK,sBAAsBZ,EAAaJ,CAAS,GAClDe,IAAoB,OAEpBV,EAAmBO,EAAyB,OACzCI,GACCA,EAAI,OAAS,uBAAqB,kBAClCA,EAAI,OAAS,uBAAqB,6BACtC,EAGIR,IACFH,EAAmB,CAACG,EAAW,GAAGH,CAAgB,WAE3CU,EAAgB,YAAa,CACtC,MAAME,EAAoBL,EAAyB,OAChDI,GACCA,EAAI,OAAS,uBAAqB,6BACtC,EACME,EAAgBN,EAAyB,OAC5CI,GAAQA,EAAI,OAAS,uBAAqB,mBAC7C,EAOAX,EAAmB,CACjB,GAP6BO,EAAyB,OACrDI,GACCA,EAAI,OAAS,uBAAqB,iBAClCA,EAAI,OAAS,uBAAqB,oBACtC,EAIE,GAAGE,EACHH,EACA,GAAGE,EACH,GAAIT,EAAY,CAACA,CAAS,EAAI,CAAC,CACjC,EACAF,EAA0B,CAAC,GAAGQ,CAAgB,EAC9CP,EAAmB,mBAAiB,OACtC,CAEA,MAAO,CACL,kBAAmBF,EACnB,0BAA2BC,EAC3B,iBAAAC,CACF,CACF,CAEQ,sBACNH,EACAJ,EACS,CACT,OAAO,IAAI,qBAAmBI,EAAaJ,CAAS,EACjD,wBAAwB,QAAQ,EAChC,mBAAmB,gBAAc,MAAM,EACvC,MAAM,CACX,CACF",
6
- "names": ["BuildBaseContexts_exports", "__export", "BuildBaseContexts", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_ClearSigningType", "import_GetChallengeCommand", "import_GetWeb3CheckTask", "import_ApplicationChecker", "_api", "_args", "getWeb3ChecksFactory", "api", "args", "contextModule", "options", "appConfig", "derivationPath", "transaction", "subset", "deviceState", "filteredContexts", "filteredContextOptional", "clearSigningType", "web3Check", "challenge", "challengeRes", "clearSignContexts", "clearSignContextsSuccess", "context", "transactionEnums", "transactionInfo", "ctx", "transactionFields", "proxyContexts"]
4
+ "sourcesContent": ["import {\n type ClearSignContext,\n type ClearSignContextSuccess,\n ClearSignContextType,\n type ContextModule,\n type TransactionSubset,\n} from \"@ledgerhq/context-module\";\nimport {\n DeviceModelId,\n type DeviceSessionState,\n type InternalApi,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { type GetConfigCommandResponse } from \"@api/app-binder/GetConfigCommandTypes\";\nimport { ClearSigningType } from \"@api/model/ClearSigningType\";\nimport { type TransactionOptions } from \"@api/model/TransactionOptions\";\nimport { GetChallengeCommand } from \"@internal/app-binder/command/GetChallengeCommand\";\nimport {\n GetWeb3CheckTask,\n type GetWeb3CheckTaskArgs,\n} from \"@internal/app-binder/task/GetWeb3CheckTask\";\nimport { ApplicationChecker } from \"@internal/shared/utils/ApplicationChecker\";\n\nexport type BuildBaseContextsResult = {\n readonly clearSignContexts: ClearSignContextSuccess[];\n readonly clearSignContextsOptional: ClearSignContextSuccess[];\n readonly clearSigningType: ClearSigningType;\n};\n\nexport type BuildBaseContextsArgs = {\n readonly contextModule: ContextModule;\n readonly options: TransactionOptions;\n readonly appConfig: GetConfigCommandResponse;\n readonly derivationPath: string;\n readonly subset: TransactionSubset;\n readonly transaction?: Uint8Array;\n};\n\n/**\n * Builds the base contexts for a transaction\n * @param api - The internal API\n * @param args - The arguments for the build\n * @param getWeb3ChecksFactory - The factory for the web3 checks\n *\n * returns the base contexts for a transaction, without subcontexts or nested call data contexts\n */\nexport class BuildBaseContexts {\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: BuildBaseContextsArgs,\n private readonly getWeb3ChecksFactory = (\n api: InternalApi,\n args: GetWeb3CheckTaskArgs,\n ) => new GetWeb3CheckTask(api, args),\n ) {}\n\n async run(): Promise<BuildBaseContextsResult> {\n const {\n contextModule,\n options,\n appConfig,\n derivationPath,\n transaction,\n subset,\n } = this._args;\n const deviceState = this._api.getDeviceSessionState();\n\n // Get challenge (not supported on Nano S)\n let challenge: string | undefined = undefined;\n if (deviceState.deviceModelId !== DeviceModelId.NANO_S) {\n const challengeRes = await this._api.sendCommand(\n new GetChallengeCommand(),\n );\n if (isSuccessCommandResult(challengeRes)) {\n challenge = challengeRes.data.challenge;\n }\n }\n\n // Get the clear sign contexts\n const clearSignContexts: ClearSignContext[] =\n await contextModule.getContexts({\n challenge: challenge,\n domain: options.domain,\n deviceModelId: deviceState.deviceModelId,\n ...subset,\n });\n\n // Run the web3checks if needed\n if (transaction && appConfig.web3ChecksEnabled) {\n const web3CheckContext = (\n await this.getWeb3ChecksFactory(this._api, {\n contextModule,\n derivationPath,\n subset,\n transaction,\n }).run()\n ).web3Check;\n if (web3CheckContext) {\n clearSignContexts.unshift(web3CheckContext);\n }\n }\n\n // filter out the error contexts\n const contextsSuccess: ClearSignContextSuccess[] = clearSignContexts.filter(\n (context) => context.type !== ClearSignContextType.ERROR,\n );\n\n if (\n this._supportsGenericParser(deviceState, appConfig) &&\n this._hasValidTransactionInfo(contextsSuccess)\n ) {\n return this._getERC7730Contexts(contextsSuccess);\n } else {\n return this._getBasicContexts(contextsSuccess);\n }\n }\n\n private _getERC7730Contexts(\n contexts: ClearSignContextSuccess[],\n ): BuildBaseContextsResult {\n const clearSignContexts: ClearSignContextSuccess[] = contexts\n .filter((context) => this._isContextNeededForERC7730ClearSigning(context))\n .sort(\n (a, b) => this._getContextPriority(a) - this._getContextPriority(b),\n );\n\n const clearSignContextsOptional: ClearSignContextSuccess[] =\n contexts.filter((context) => context.type === ClearSignContextType.ENUM);\n\n return {\n clearSignContexts,\n clearSignContextsOptional,\n clearSigningType: ClearSigningType.EIP7730,\n };\n }\n\n private _getBasicContexts(\n contexts: ClearSignContextSuccess[],\n ): BuildBaseContextsResult {\n const clearSignContexts: ClearSignContextSuccess[] = contexts\n .filter((context) => this._isContextNeededForBasicClearSigning(context))\n .sort(\n (a, b) => this._getContextPriority(a) - this._getContextPriority(b),\n );\n\n return {\n clearSignContexts,\n clearSignContextsOptional: [],\n clearSigningType: ClearSigningType.BASIC,\n };\n }\n\n private _isContextNeededForBasicClearSigning({\n type,\n }: ClearSignContextSuccess): boolean {\n switch (type) {\n case ClearSignContextType.WEB3_CHECK:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n return true;\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.ENUM:\n case ClearSignContextType.PROXY_INFO:\n return false;\n default: {\n const uncoveredType: never = type;\n throw new Error(`Unhandled context type ${String(uncoveredType)}`);\n }\n }\n }\n\n private _isContextNeededForERC7730ClearSigning({\n type,\n }: ClearSignContextSuccess): boolean {\n switch (type) {\n case ClearSignContextType.TRANSACTION_INFO:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.PROXY_INFO:\n case ClearSignContextType.WEB3_CHECK:\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n return true;\n case ClearSignContextType.ENUM: // enum is needed but as optional\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n return false;\n default: {\n const uncoveredType: never = type;\n throw new Error(`Unhandled context type ${String(uncoveredType)}`);\n }\n }\n }\n\n private _hasValidTransactionInfo(\n contexts: ClearSignContextSuccess[],\n ): boolean {\n return (\n contexts.find(\n (context) => context.type === ClearSignContextType.TRANSACTION_INFO,\n )?.certificate !== undefined\n );\n }\n\n private _supportsGenericParser(\n deviceState: DeviceSessionState,\n appConfig: GetConfigCommandResponse,\n ): boolean {\n return new ApplicationChecker(deviceState, appConfig)\n .withMinVersionExclusive(\"1.14.0\")\n .excludeDeviceModel(DeviceModelId.NANO_S)\n .check();\n }\n\n /**\n * Determines the processing priority of a clear sign context.\n * Lower numbers indicate higher priority (processed first).\n *\n * @param context The clear sign context to get priority for\n * @returns Priority number (lower = higher priority)\n */\n private _getContextPriority({ type }: ClearSignContextSuccess): number {\n switch (type) {\n case ClearSignContextType.WEB3_CHECK:\n return 10;\n case ClearSignContextType.DYNAMIC_NETWORK:\n case ClearSignContextType.DYNAMIC_NETWORK_ICON:\n case ClearSignContextType.PROXY_INFO:\n return 30;\n case ClearSignContextType.TRANSACTION_INFO:\n return 50;\n case ClearSignContextType.PLUGIN:\n case ClearSignContextType.EXTERNAL_PLUGIN:\n case ClearSignContextType.TOKEN:\n case ClearSignContextType.NFT:\n case ClearSignContextType.TRUSTED_NAME:\n case ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION:\n case ClearSignContextType.ENUM:\n return 70;\n\n default: {\n const uncoveredType: never = type;\n throw new Error(\n `Unhandled context type for priority: ${String(uncoveredType)}`,\n );\n }\n }\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAMO,oCACPC,EAKO,2CAGPC,EAAiC,uCAEjCC,EAAoC,4DACpCC,EAGO,sDACPC,EAAmC,qDAyB5B,MAAMP,CAAkB,CAC7B,YACmBQ,EACAC,EACAC,EAAuB,CACtCC,EACAC,IACG,IAAI,mBAAiBD,EAAKC,CAAI,EACnC,CANiB,UAAAJ,EACA,WAAAC,EACA,0BAAAC,CAIhB,CAEH,MAAM,KAAwC,CAC5C,KAAM,CACJ,cAAAG,EACA,QAAAC,EACA,UAAAC,EACA,eAAAC,EACA,YAAAC,EACA,OAAAC,CACF,EAAI,KAAK,MACHC,EAAc,KAAK,KAAK,sBAAsB,EAGpD,IAAIC,EACJ,GAAID,EAAY,gBAAkB,gBAAc,OAAQ,CACtD,MAAME,EAAe,MAAM,KAAK,KAAK,YACnC,IAAI,qBACN,KACI,0BAAuBA,CAAY,IACrCD,EAAYC,EAAa,KAAK,UAElC,CAGA,MAAMC,EACJ,M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K,uBAAqB,IAC1B,KAAK,uBAAqB,aAC1B,KAAK,uBAAqB,8BAC1B,KAAK,uBAAqB,KACxB,MAAO,IAET,QAAS,CACP,MAAMC,EAAuBD,EAC7B,MAAM,IAAI,MACR,wCAAwC,OAAOC,CAAa,CAAC,EAC/D,CACF,CACF,CACF,CACF",
6
+ "names": ["BuildBaseContexts_exports", "__export", "BuildBaseContexts", "__toCommonJS", "import_context_module", "import_device_management_kit", "import_ClearSigningType", "import_GetChallengeCommand", "import_GetWeb3CheckTask", "import_ApplicationChecker", "_api", "_args", "getWeb3ChecksFactory", "api", "args", "contextModule", "options", "appConfig", "derivationPath", "transaction", "subset", "deviceState", "challenge", "challengeRes", "clearSignContexts", "web3CheckContext", "contextsSuccess", "context", "contexts", "a", "b", "clearSignContextsOptional", "type", "uncoveredType"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var n=require("@ledgerhq/context-module"),t=require("@ledgerhq/device-management-kit"),S=require("ethers"),d=require("../../../api/model/ClearSigningType"),y=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),s=require("./BuildBaseContexts"),g=require("./GetWeb3CheckTask");describe("BuildBaseContexts",()=>{const l={getFieldContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn(),getSolanaContext:vi.fn()},x={domain:"domain-name.eth"},C=(0,t.hexaStringToBuffer)(S.Transaction.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),r={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let c;const a=(0,y.makeDeviceActionInternalApiMock)(),i=vi.fn();function u(e){return{blindSigningEnabled:!1,web3ChecksEnabled:e,web3ChecksOptIn:!1,version:"1.13.0"}}beforeEach(()=>{vi.resetAllMocks(),a.sendCommand.mockResolvedValue((0,t.CommandResultFactory)({data:{challenge:"challenge"}})),i.mockReturnValue({run:async()=>Promise.resolve({web3Check:null})}),c={contextModule:l,subset:{chainId:1,to:void 0,data:"0x",selector:"0x"},transaction:C,options:x,appConfig:u(!1),derivationPath:"44'/60'/0'/0/0"}}),it("should init with a default GetWeb3CheckTaskFactory",()=>{const e=new s.BuildBaseContexts(a,c);expect(e.getWeb3ChecksFactory).toBeDefined(),expect(e.getWeb3ChecksFactory(a,{contextModule:c.contextModule,derivationPath:c.derivationPath,subset:c.subset,transaction:c.transaction})).toBeInstanceOf(g.GetWeb3CheckTask)}),it("should build the transaction context without clear sign contexts",async()=>{const e=[],o=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks",async()=>{const e=[],o=[],p="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:p})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const E=await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(E).toEqual({clearSignContexts:[p,...e],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[e[0],e[1],e[3],o],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order",async()=>{const e=[{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[e[3],e[1],e[2],o],clearSignContextsOptional:[e[0]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.NFT,payload:"payload-2"}],o="web3Check";i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,c,i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with generic-parser context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with proxy delegate call context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.PROXY_DELEGATE_CALL,payload:"payload-2"}],o=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,c,i).run();expect(p).toEqual({clearSignContexts:[e[1],e[0]],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.EIP7730})}),it("should call the web3checks factory with correct parameters",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run(),expect(i).toHaveBeenCalledWith(a,{contextModule:l,derivationPath:"44'/60'/0'/0/0",subset:c.subset,transaction:C})}),it("should call the context module with the correct parameters",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new s.BuildBaseContexts(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:"challenge",domain:"domain-name.eth",...c.subset})}),it("should call the context module without challenge for Nano S",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1}),await new s.BuildBaseContexts(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.NANO_S,domain:"domain-name.eth",...c.subset})}),it("should call the context module without context on error",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),a.sendCommand.mockResolvedValueOnce((0,t.CommandResultFactory)({error:new t.UnknownDeviceExchangeError})),await new s.BuildBaseContexts(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:void 0,domain:"domain-name.eth",...c.subset})}),it("should exclude error contexts from the result",async()=>{const e=[{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"transaction_info",certificate:r},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.NFT,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.EXTERNAL_PLUGIN,payload:"payload-3"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.ENUM,payload:"payload-5",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[e[4]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with an old app version",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.Connected,deviceStatus:t.DeviceStatus.NOT_CONNECTED,deviceModelId:t.DeviceModelId.FLEX});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should return no clear sign context if the transaction info certificate is missing",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should not return web3check if the transaction is undefined",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new s.BuildBaseContexts(a,{...c,transaction:void 0},i).run(),expect(i).not.toHaveBeenCalled()})});
1
+ "use strict";var n=require("@ledgerhq/context-module"),t=require("@ledgerhq/device-management-kit"),S=require("ethers"),d=require("../../../api/model/ClearSigningType"),y=require("../../app-binder/device-action/__test-utils__/makeInternalApi"),s=require("./BuildBaseContexts"),g=require("./GetWeb3CheckTask");describe("BuildBaseContexts",()=>{const l={getFieldContext:vi.fn(),getContexts:vi.fn(),getTypedDataFilters:vi.fn(),getWeb3Checks:vi.fn(),getSolanaContext:vi.fn()},x={domain:"domain-name.eth"},C=(0,t.hexaStringToBuffer)(S.Transaction.from({chainId:1n,nonce:0,data:"0x"}).unsignedSerialized),r={keyUsageNumber:1,payload:new Uint8Array([1,2,3])};let c;const a=(0,y.makeDeviceActionInternalApiMock)(),i=vi.fn();function u(e){return{blindSigningEnabled:!1,web3ChecksEnabled:e,web3ChecksOptIn:!1,version:"1.13.0"}}beforeEach(()=>{vi.resetAllMocks(),a.sendCommand.mockResolvedValue((0,t.CommandResultFactory)({data:{challenge:"challenge"}})),i.mockReturnValue({run:async()=>Promise.resolve({web3Check:null})}),c={contextModule:l,subset:{chainId:1,to:void 0,data:"0x",selector:"0x"},transaction:C,options:x,appConfig:u(!1),derivationPath:"44'/60'/0'/0/0"}}),it("should init with a default GetWeb3CheckTaskFactory",()=>{const e=new s.BuildBaseContexts(a,c);expect(e.getWeb3ChecksFactory).toBeDefined(),expect(e.getWeb3ChecksFactory(a,{contextModule:c.contextModule,derivationPath:c.derivationPath,subset:c.subset,transaction:c.transaction})).toBeInstanceOf(g.GetWeb3CheckTask)}),it("should build the transaction context without clear sign contexts",async()=>{const e=[],o=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks",async()=>{const e=[],o=[],p={type:n.ClearSignContextType.WEB3_CHECK,payload:"web3Check"};i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:p})}),l.getContexts.mockResolvedValueOnce([...e]),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const E=await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(E).toEqual({clearSignContexts:[p,...e],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}],o={type:n.ClearSignContextType.WEB3_CHECK,payload:"web3Check"};i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce([...e]),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[o,e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with web3checks and generic-parser clear sign contexts in the correct order",async()=>{const e=[{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r}],o={type:n.ClearSignContextType.WEB3_CHECK,payload:"web3Check"};i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce([...e]),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run();expect(p).toEqual({clearSignContexts:[o,e[3],e[1],e[2]],clearSignContextsOptional:[e[0]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with clear sign contexts",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.NFT,payload:"payload-2"}],o={type:n.ClearSignContextType.WEB3_CHECK,payload:"web3Check"};i.mockReturnValueOnce({run:async()=>Promise.resolve({web3Check:o})}),l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,c,i).run();expect(p).toEqual({clearSignContexts:e,clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should build the transaction context with generic-parser context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2,certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0],e[1],e[3]],clearSignContextsOptional:[e[2]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should build the transaction context with proxy delegate call context",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1",certificate:r},{type:n.ClearSignContextType.PROXY_INFO,payload:"payload-2"}],o=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const p=await new s.BuildBaseContexts(a,c,i).run();expect(p).toEqual({clearSignContexts:[e[1],e[0]],clearSignContextsOptional:o,clearSigningType:d.ClearSigningType.EIP7730})}),it("should call the web3checks factory with correct parameters",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new s.BuildBaseContexts(a,{...c,appConfig:u(!0)},i).run(),expect(i).toHaveBeenCalledWith(a,{contextModule:l,derivationPath:"44'/60'/0'/0/0",subset:c.subset,transaction:C})}),it("should call the context module with the correct parameters",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new s.BuildBaseContexts(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:"challenge",domain:"domain-name.eth",...c.subset})}),it("should call the context module without challenge for Nano S",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1}),await new s.BuildBaseContexts(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.NANO_S,domain:"domain-name.eth",...c.subset})}),it("should call the context module without context on error",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),a.sendCommand.mockResolvedValueOnce((0,t.CommandResultFactory)({error:new t.UnknownDeviceExchangeError})),await new s.BuildBaseContexts(a,c,i).run(),expect(l.getContexts).toHaveBeenCalledWith({deviceModelId:t.DeviceModelId.FLEX,challenge:void 0,domain:"domain-name.eth",...c.subset})}),it("should exclude error contexts from the result",async()=>{const e=[{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ERROR,error:new Error("error")},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result on old apps",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"transaction_info",certificate:r},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.NFT,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts from the result if no transaction_info was found",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"transaction_field"},{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.ENUM,payload:"enum",id:1,value:2},{type:n.ClearSignContextType.NFT,payload:"payload-2"}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude legacy contexts from the result for generic-parser transactions",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.EXTERNAL_PLUGIN,payload:"payload-3"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-4"},{type:n.ClearSignContextType.ENUM,payload:"payload-5",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.15.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[1],e[3]],clearSignContextsOptional:[e[4]],clearSigningType:d.ClearSigningType.EIP7730})}),it("should exclude generic-parser contexts with a nano s device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.14.0"},deviceModelId:t.DeviceModelId.NANO_S,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with an old app version",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.12.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should exclude generic-parser contexts with a non ready device",async()=>{const e=[{type:n.ClearSignContextType.TOKEN,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-2",certificate:r},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-3"},{type:n.ClearSignContextType.ENUM,payload:"payload-4",id:1,value:2,certificate:r}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.Connected,deviceStatus:t.DeviceStatus.NOT_CONNECTED,deviceModelId:t.DeviceModelId.FLEX});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[e[0]],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should return no clear sign context if the transaction info certificate is missing",async()=>{const e=[{type:n.ClearSignContextType.TRANSACTION_INFO,payload:"payload-1"},{type:n.ClearSignContextType.TRANSACTION_FIELD_DESCRIPTION,payload:"payload-2"},{type:n.ClearSignContextType.ENUM,payload:"payload-3",id:1,value:2}];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1});const o=await new s.BuildBaseContexts(a,c,i).run();expect(o).toEqual({clearSignContexts:[],clearSignContextsOptional:[],clearSigningType:d.ClearSigningType.BASIC})}),it("should not return web3check if the transaction is undefined",async()=>{const e=[];l.getContexts.mockResolvedValueOnce(e),a.getDeviceSessionState.mockReturnValueOnce({sessionStateType:t.DeviceSessionStateType.ReadyWithoutSecureChannel,deviceStatus:t.DeviceStatus.CONNECTED,installedApps:[],currentApp:{name:"Ethereum",version:"1.17.0"},deviceModelId:t.DeviceModelId.FLEX,isSecureConnectionAllowed:!1}),await new s.BuildBaseContexts(a,{...c,transaction:void 0},i).run(),expect(i).not.toHaveBeenCalled()})});
2
2
  //# sourceMappingURL=BuildBaseContexts.test.js.map