diff --git a/src/eth/index.ts b/src/eth/index.ts index a7e4b147d..0e8ad0329 100644 --- a/src/eth/index.ts +++ b/src/eth/index.ts @@ -1,2 +1,3 @@ export * from './erc4337'; export * from './types'; +export * from './utils'; diff --git a/src/eth/utils.test.ts b/src/eth/utils.test.ts new file mode 100644 index 000000000..98cf97fc5 --- /dev/null +++ b/src/eth/utils.test.ts @@ -0,0 +1,17 @@ +import { EthAccountType } from '.'; +import { BtcAccountType } from '../btc'; +import { isEvmAccountType } from './utils'; + +describe('isEvmAccountType', () => { + it.each([ + [EthAccountType.Eoa, true], + [EthAccountType.Erc4337, true], + [BtcAccountType.P2wpkh, false], + [{}, false], + [null, false], + ['bitcoin', false], + ])('%s should return %s', (account, result) => { + // @ts-expect-error for error cases + expect(isEvmAccountType(account)).toBe(result); + }); +}); diff --git a/src/eth/utils.ts b/src/eth/utils.ts new file mode 100644 index 000000000..072c60bac --- /dev/null +++ b/src/eth/utils.ts @@ -0,0 +1,11 @@ +import type { InternalAccountType } from '../internal'; +import { EthAccountType } from './types'; + +/** + * Checks if the given type is an EVM account type. + * @param type - The type to check. + * @returns Returns true if the type is an EVM account type, false otherwise. + */ +export function isEvmAccountType(type: InternalAccountType): boolean { + return type === EthAccountType.Eoa || type === EthAccountType.Erc4337; +} diff --git a/src/internal/types.ts b/src/internal/types.ts index a5c24bf10..9ee0ca0ef 100644 --- a/src/internal/types.ts +++ b/src/internal/types.ts @@ -10,6 +10,8 @@ import { } from '../eth/types'; import { exactOptional, object } from '../superstruct'; +export type InternalAccountType = EthAccountType | BtcAccountType; + export const InternalAccountMetadataStruct = object({ metadata: object({ name: string(), @@ -75,7 +77,12 @@ export const InternalAccountStructs: Record< [`${BtcAccountType.P2wpkh}`]: InternalBtcP2wpkhAccountStruct, }; -export const InternalAccountStruct = define( +export type InternalAccountTypes = + | InternalEthEoaAccount + | InternalEthErc4337Account + | InternalBtcP2wpkhAccount; + +export const InternalAccountStruct = define( 'InternalAccount', (value: unknown) => { const account = mask(value, BaseKeyringAccountStruct);