From d630b138d6d1f9a7d8c8f5c85689dde68b77207d Mon Sep 17 00:00:00 2001 From: Chaitanya Potti Date: Mon, 12 Aug 2024 12:37:28 +0800 Subject: [PATCH] remove dynamic import of eth sig util --- .../src/providers/signingProviders/signingUtils.ts | 10 ++++++++-- .../privateKeyProviders/TransactionFormatter/utils.ts | 4 ++-- .../privateKeyProviders/ethPrivatekeyUtils.ts | 6 +----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/providers/ethereum-mpc-provider/src/providers/signingProviders/signingUtils.ts b/packages/providers/ethereum-mpc-provider/src/providers/signingProviders/signingUtils.ts index c79cd0b65..f9ff40b65 100644 --- a/packages/providers/ethereum-mpc-provider/src/providers/signingProviders/signingUtils.ts +++ b/packages/providers/ethereum-mpc-provider/src/providers/signingProviders/signingUtils.ts @@ -1,5 +1,12 @@ import { hashPersonalMessage, intToBytes, isHexString, publicToAddress, stripHexPrefix, toBytes } from "@ethereumjs/util"; -import type { MessageTypes, TypedDataV1, TypedDataV1Field, TypedMessage } from "@metamask/eth-sig-util"; +import { + type MessageTypes, + TypedDataUtils, + type TypedDataV1, + type TypedDataV1Field, + type TypedMessage, + typedSignatureHash, +} from "@metamask/eth-sig-util"; import { providerErrors } from "@metamask/rpc-errors"; import { concatSig } from "@toruslabs/base-controllers"; import { JRPCRequest, SafeEventEmitterProvider } from "@toruslabs/openlogin-jrpc"; @@ -121,7 +128,6 @@ async function signTypedData( if (data === null || data === undefined) { throw new Error("Missing data parameter"); } - const { TypedDataUtils, typedSignatureHash } = await import("@metamask/eth-sig-util"); const messageHash = version === SignTypedDataVersion.V1 ? Buffer.from(stripHexPrefix(typedSignatureHash(data as TypedDataV1Field[])), "hex") diff --git a/packages/providers/ethereum-provider/src/providers/privateKeyProviders/TransactionFormatter/utils.ts b/packages/providers/ethereum-provider/src/providers/privateKeyProviders/TransactionFormatter/utils.ts index cbb3d2247..590ebbd9c 100644 --- a/packages/providers/ethereum-provider/src/providers/privateKeyProviders/TransactionFormatter/utils.ts +++ b/packages/providers/ethereum-provider/src/providers/privateKeyProviders/TransactionFormatter/utils.ts @@ -1,5 +1,5 @@ import { isValidAddress } from "@ethereumjs/util"; -import type { MessageTypeProperty, TypedDataV1Field, TypedMessage } from "@metamask/eth-sig-util"; +import { type MessageTypeProperty, TYPED_MESSAGE_SCHEMA, type TypedDataV1Field, type TypedMessage, typedSignatureHash } from "@metamask/eth-sig-util"; import { rpcErrors } from "@metamask/rpc-errors"; import { get } from "@toruslabs/http-helpers"; import { isHexStrict } from "@web3auth/base"; @@ -73,7 +73,7 @@ export const validateTypedMessageParams = async (parameters: TypedMessageParams< ); let data: unknown = null; let chainId = null; - const { typedSignatureHash, TYPED_MESSAGE_SCHEMA } = await import("@metamask/eth-sig-util"); + switch ((parameters as TypedMessageParams).version) { case SignTypedDataVersion.V1: if (typeof parameters.data === "string") { diff --git a/packages/providers/ethereum-provider/src/providers/privateKeyProviders/ethPrivatekeyUtils.ts b/packages/providers/ethereum-provider/src/providers/privateKeyProviders/ethPrivatekeyUtils.ts index 18dcb9306..66a78a36c 100644 --- a/packages/providers/ethereum-provider/src/providers/privateKeyProviders/ethPrivatekeyUtils.ts +++ b/packages/providers/ethereum-provider/src/providers/privateKeyProviders/ethPrivatekeyUtils.ts @@ -1,5 +1,5 @@ import { privateToAddress } from "@ethereumjs/util"; -import type { MessageTypes, TypedDataV1, TypedMessage } from "@metamask/eth-sig-util"; +import { type MessageTypes, personalSign, signTypedData, type TypedDataV1, type TypedMessage } from "@metamask/eth-sig-util"; import { providerErrors } from "@metamask/rpc-errors"; import { signMessage } from "@toruslabs/base-controllers"; import { JRPCRequest } from "@toruslabs/openlogin-jrpc"; @@ -65,7 +65,6 @@ export function getProviderHandlers({ }, processPersonalMessage: async (msgParams: MessageParams, _: JRPCRequest): Promise => { const privKeyBuffer = Buffer.from(privKey, "hex"); - const { personalSign } = await import("@metamask/eth-sig-util"); const sig = personalSign({ privateKey: privKeyBuffer, data: msgParams.data }); return sig; }, @@ -85,7 +84,6 @@ export function getProviderHandlers({ version: SignTypedDataVersion.V1, }; await validateTypedMessageParams(params, finalChainId); - const { signTypedData } = await import("@metamask/eth-sig-util"); const data = typeof params.data === "string" ? JSON.parse(params.data) : params.data; const sig = signTypedData({ privateKey: privKeyBuffer, data, version: SignTypedDataVersion.V1 }); return sig; @@ -103,7 +101,6 @@ export function getProviderHandlers({ const finalChainId = Number.parseInt(chainId, isHexStrict(chainId) ? 16 : 10); await validateTypedMessageParams(msgParams, finalChainId); const data = typeof msgParams.data === "string" ? JSON.parse(msgParams.data) : msgParams.data; - const { signTypedData } = await import("@metamask/eth-sig-util"); const sig = signTypedData({ privateKey: privKeyBuffer, data, version: SignTypedDataVersion.V3 }); return sig; }, @@ -120,7 +117,6 @@ export function getProviderHandlers({ const finalChainId = Number.parseInt(chainId, isHexStrict(chainId) ? 16 : 10); await validateTypedMessageParams(msgParams, finalChainId); const data = typeof msgParams.data === "string" ? JSON.parse(msgParams.data) : msgParams.data; - const { signTypedData } = await import("@metamask/eth-sig-util"); const sig = signTypedData({ privateKey: privKeyBuffer, data, version: SignTypedDataVersion.V4 }); return sig; },