diff --git a/apps/popup/src/lib/account-abstraction/account-adapters/to-universal-account.ts b/apps/popup/src/lib/account-abstraction/account-adapters/to-universal-account.ts index 129c2b40..3c0fb859 100644 --- a/apps/popup/src/lib/account-abstraction/account-adapters/to-universal-account.ts +++ b/apps/popup/src/lib/account-abstraction/account-adapters/to-universal-account.ts @@ -1,5 +1,5 @@ import type { Address, TypedData } from 'abitype'; -import { universalDeployments } from 'universal-data'; +import { isValidChain, universalDeployments } from 'universal-data'; import { type Assign, BaseError, @@ -244,11 +244,16 @@ export async function toUniversalAccount( const { chainId, ...userOperation } = parameters; const address = await this.getAddress(); + if (!isValidChain(chainId)) { + throw new BaseError('Invalid chainId'); + } + // @ts-ignore const packedUserOperationHash = getUserOperationHash(userOperation); const packedUserOpTypedHash = getPackedUserOperationTypedDataHash({ address, + chainId, packedUserOperationHash, }); diff --git a/apps/popup/src/lib/account-abstraction/utils.ts b/apps/popup/src/lib/account-abstraction/utils.ts index b941c56e..5ac2a636 100644 --- a/apps/popup/src/lib/account-abstraction/utils.ts +++ b/apps/popup/src/lib/account-abstraction/utils.ts @@ -191,13 +191,15 @@ export function getUserOperationHash(params: UserOperationParams): Hex { export function getPackedUserOperationTypedDataHash({ address, + chainId, packedUserOperationHash, }: { address: Address; + chainId: number; packedUserOperationHash: Hex; }): Hex { const parts: Hex[] = ['0x1901']; - const domainSeparator = buildDomainSeparator({ address, chainId: 84532 }); + const domainSeparator = buildDomainSeparator({ address, chainId }); parts.push(domainSeparator); parts.push(packedUserOperationHash); diff --git a/packages/universal-data/src/chains.ts b/packages/universal-data/src/chains.ts index 504bd8ba..c35164de 100644 --- a/packages/universal-data/src/chains.ts +++ b/packages/universal-data/src/chains.ts @@ -34,7 +34,12 @@ export function isTestnetChain(chainId: number): chainId is TestnetChain['id'] { return testnetChainIds.includes(chainId as TestnetChain['id']); } -export function isValidChain(chainId: number): chainId is ValidChain['id'] { +export function isValidChain( + chainId: number | undefined, +): chainId is ValidChain['id'] { + if (chainId === undefined) { + return false; + } return isProductionChain(chainId) || isTestnetChain(chainId); }