From 22c73f7ef727a6ffc00709a8df8f63fb35a7a4b0 Mon Sep 17 00:00:00 2001 From: Chaitanya Potti Date: Thu, 24 Oct 2024 07:56:59 +0800 Subject: [PATCH] use viem fully for managing typed signing --- .../src/providers/utils.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/packages/providers/account-abstraction-provider/src/providers/utils.ts b/packages/providers/account-abstraction-provider/src/providers/utils.ts index 21d2b63f7..cb5bfc744 100644 --- a/packages/providers/account-abstraction-provider/src/providers/utils.ts +++ b/packages/providers/account-abstraction-provider/src/providers/utils.ts @@ -3,7 +3,6 @@ import { sleep } from "@toruslabs/base-controllers"; import { JRPCRequest, providerErrors } from "@web3auth/auth"; import { IProvider, log } from "@web3auth/base"; import { IProviderHandlers, MessageParams, SignTypedDataMessageV4, TransactionParams, TypedMessageParams } from "@web3auth/ethereum-provider"; -import { TypedDataEncoder } from "ethers"; import { Chain, createWalletClient, Hex, http } from "viem"; import { BundlerClient, SendUserOperationParameters, SmartAccount } from "viem/account-abstraction"; @@ -184,16 +183,8 @@ export function getProviderHandlers({ }, processTypedMessageV4: async (msgParams: TypedMessageParams, _: JRPCRequest): Promise => { try { - const data: SignTypedDataMessageV4 = typeof msgParams.data === "string" ? JSON.parse(msgParams.data) : msgParams.data; - - // Deduce the primary type using ethers - // remove EIP712Domain from types if it exists - // ethers already take care of EIP712Domain type and doesn't allow initiating with it - if (data.types.EIP712Domain) { - delete data.types.EIP712Domain; - } - const typedData = TypedDataEncoder.from(data.types); - const { primaryType } = typedData; + const data: SignTypedDataMessageV4 & { primaryType: string } = + typeof msgParams.data === "string" ? JSON.parse(msgParams.data) : msgParams.data; const signature = await walletClient.signTypedData({ account: smartAccount, domain: { @@ -202,7 +193,7 @@ export function getProviderHandlers({ salt: data.domain.salt as Hex, chainId: Number(data.domain.chainId), }, - primaryType, + primaryType: data.primaryType, types: data.types, message: data.message, });