Skip to content

Commit

Permalink
fix: validateTypeData for ethereum provider
Browse files Browse the repository at this point in the history
  • Loading branch information
ieow committed Jan 10, 2025
1 parent c85c089 commit 085d851
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/providers/ethereum-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"bignumber.js": "^9.1.2",
"bn.js": "^5.2.1",
"ethers": "^6.13.4",
"jsonschema": "^1.4.1"
"jsonschema": "^1.4.1",
"viem": "^2.22.5"
},
"devDependencies": {
"@types/bn.js": "^5.1.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { signMessage } from "@toruslabs/base-controllers";
import { getPublicCompressed } from "@toruslabs/eccrypto";
import { JRPCRequest, providerErrors } from "@web3auth/auth";
import { log, SafeEventEmitterProvider } from "@web3auth/base";
import { hashMessage, SigningKey, TypedDataEncoder } from "ethers";
import { hashMessage, SigningKey } from "ethers";
import { hashTypedData, validateTypedData } from "viem";

import { IProviderHandlers, MessageParams, SignTypedDataMessageV4, TransactionParams, TypedMessageParams } from "../../rpc/interfaces";
import { IProviderHandlers, MessageParams, TransactionParams, TypedMessageParams } from "../../rpc/interfaces";
import { TransactionFormatter } from "./TransactionFormatter/formatter";
import { validateTypedSignMessageDataV4 } from "./TransactionFormatter/utils";

Expand Down Expand Up @@ -103,10 +104,10 @@ export function getProviderHandlers({
});
const chainId = await providerEngineProxy.request<never, string>({ method: "eth_chainId" });
await validateTypedSignMessageDataV4(msgParams, chainId);
const data: SignTypedDataMessageV4 = typeof msgParams.data === "string" ? JSON.parse(msgParams.data) : msgParams.data;
const data = typeof msgParams.data === "string" ? JSON.parse(msgParams.data) : msgParams.data;
const ethersPrivateKey = new SigningKey(privKeyBuffer);
if (data.types.EIP712Domain) delete data.types.EIP712Domain;
const signature = ethersPrivateKey.sign(TypedDataEncoder.hash(data.domain, data.types, data.message)).serialized;
validateTypedData(data);
const signature = ethersPrivateKey.sign(hashTypedData(data)).serialized;
return signature;
},
};
Expand Down

0 comments on commit 085d851

Please sign in to comment.