Skip to content

Commit

Permalink
fix: add multi-chain support for sign user operation
Browse files Browse the repository at this point in the history
  • Loading branch information
marthendalnunes committed Dec 3, 2024
1 parent e6c1180 commit cabf9fb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
});

Expand Down
4 changes: 3 additions & 1 deletion apps/popup/src/lib/account-abstraction/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 6 additions & 1 deletion packages/universal-data/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit cabf9fb

Please sign in to comment.