From 8ffd019b49e08f6cb7f7075cd48564a09cafbefd Mon Sep 17 00:00:00 2001 From: Daniel Rocha <68558152+danroc@users.noreply.github.com> Date: Fri, 1 Dec 2023 10:47:23 +0100 Subject: [PATCH] feat: add `EthKeyring` type --- jest.config.js | 6 ++++- src/internal/eth/EthKeyring.ts | 44 ++++++++++++++++++++++++++++++++++ src/internal/eth/index.ts | 1 + 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/internal/eth/EthKeyring.ts create mode 100644 src/internal/eth/index.ts diff --git a/jest.config.js b/jest.config.js index cef3c14f9..bd7fddb65 100644 --- a/jest.config.js +++ b/jest.config.js @@ -22,7 +22,11 @@ module.exports = { collectCoverage: true, // An array of glob patterns indicating a set of files for which coverage information should be collected - collectCoverageFrom: ['./src/**/*.ts', '!./src/**/*.test-d.ts'], + collectCoverageFrom: [ + './src/**/*.ts', + '!./src/**/index.ts', + '!./src/**/*.test-d.ts', + ], // The directory where Jest should output its coverage files coverageDirectory: 'coverage', diff --git a/src/internal/eth/EthKeyring.ts b/src/internal/eth/EthKeyring.ts new file mode 100644 index 000000000..86513edc7 --- /dev/null +++ b/src/internal/eth/EthKeyring.ts @@ -0,0 +1,44 @@ +import type { Json, Keyring } from '@metamask/utils'; + +import type { + EthBaseTransaction, + EthBaseUserOperation, + EthUserOperation, + EthUserOperationPatch, +} from '../../eth'; + +export type EthKeyring = Keyring & { + /** + * Convert a base transaction to a base UserOperation. + * + * @param address - Address of the sender. + * @param transactions - Base transactions to include in the UserOperation. + * @returns A pseudo-UserOperation that can be used to construct a real. + */ + prepareUserOperation( + address: string, + transactions: EthBaseTransaction[], + ): Promise; + + /** + * Patches properties of a UserOperation. Currently, only the + * `paymasterAndData` can be patched. + * + * @param address - Address of the sender. + * @param userOp - UserOperation to patch. + * @returns A patch to apply to the UserOperation. + */ + patchUserOperation( + address: string, + userOp: EthUserOperation, + ): Promise; + + /** + * Signs an UserOperation. + * + * @param address - Address of the sender. + * @param userOp - UserOperation to sign. + * @returns The signature of the UserOperation. + */ + signUserOperation(address: string, userOp: EthUserOperation): Promise; +}; diff --git a/src/internal/eth/index.ts b/src/internal/eth/index.ts new file mode 100644 index 000000000..fa5f8282c --- /dev/null +++ b/src/internal/eth/index.ts @@ -0,0 +1 @@ +export * from './EthKeyring';