Skip to content

Commit

Permalink
fix: resolves wevm/viem#2306
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Jun 6, 2024
1 parent 8acf564 commit e030281
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/thirdweb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
"mipd": "0.0.7",
"node-libs-browser": "2.2.1",
"uqr": "0.1.2",
"viem": "2.10.9"
"viem": "2.13.7"
},
"peerDependencies": {
"@aws-sdk/client-lambda": "^3",
Expand Down Expand Up @@ -310,4 +310,4 @@
"shamir-secret-sharing": "0.0.3",
"vitest": "1.5.0"
}
}
}
13 changes: 7 additions & 6 deletions packages/thirdweb/src/wallets/coinbase/coinbaseSDKWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import type { Address } from "abitype";
import {
type SignTypedDataParameters,
getTypesForEIP712Domain,
serializeTypedData,
validateTypedData,
} from "viem";
import { stringify } from "../../utils/json.js";
import type { Account, Wallet } from "../interfaces/wallet.js";
import type { SendTransactionOption } from "../interfaces/wallet.js";
import type { AppMetadata, DisconnectFn, SwitchChainFn } from "../types.js";
Expand All @@ -22,7 +22,6 @@ import type { ThirdwebClient } from "../../client/client.js";
import { getAddress } from "../../utils/address.js";
import {
type Hex,
isHex,
numberToHex,
stringToHex,
uint8ArrayToHex,
Expand Down Expand Up @@ -333,10 +332,12 @@ function createAccount(provider: ProviderInterface, address: string) {
// as we can't statically check this with TypeScript.
validateTypedData({ domain, message, primaryType, types });

const stringifiedData = stringify(
{ domain: domain ?? {}, message, primaryType, types },
(_, value) => (isHex(value) ? value.toLowerCase() : value),
);
const stringifiedData = serializeTypedData({
domain: domain ?? {},
message,
primaryType,
types,
});

return await provider.request({
method: "eth_signTypedData_v4",
Expand Down
13 changes: 7 additions & 6 deletions packages/thirdweb/src/wallets/injected/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@ import type { Address } from "abitype";
import {
type SignTypedDataParameters,
getTypesForEIP712Domain,
serializeTypedData,
validateTypedData,
} from "viem";
import type { Chain } from "../../chains/types.js";
import { getCachedChain, getChainMetadata } from "../../chains/utils.js";
import { getAddress } from "../../utils/address.js";
import {
type Hex,
isHex,
numberToHex,
stringToHex,
uint8ArrayToHex,
} from "../../utils/encoding/hex.js";
import { stringify } from "../../utils/json.js";
import type { Ethereum } from "../interfaces/ethereum.js";
import type {
Account,
Expand Down Expand Up @@ -185,10 +184,12 @@ function createAccount(provider: Ethereum, address: string) {
// as we can't statically check this with TypeScript.
validateTypedData({ domain, message, primaryType, types });

const stringifiedData = stringify(
{ domain: domain ?? {}, message, primaryType, types },
(_, value) => (isHex(value) ? value.toLowerCase() : value),
);
const stringifiedData = serializeTypedData({
domain: domain ?? {},
message,
primaryType,
types,
});

return await provider.request({
method: "eth_signTypedData_v4",
Expand Down
13 changes: 7 additions & 6 deletions packages/thirdweb/src/wallets/wallet-connect/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
SwitchChainError,
UserRejectedRequestError,
getTypesForEIP712Domain,
serializeTypedData,
validateTypedData,
} from "viem";
import type { Chain } from "../../chains/types.js";
Expand All @@ -16,12 +17,10 @@ import {
} from "../../chains/utils.js";
import {
type Hex,
isHex,
numberToHex,
stringToHex,
uint8ArrayToHex,
} from "../../utils/encoding/hex.js";
import { stringify } from "../../utils/json.js";
import { isAndroid, isIOS, isMobile } from "../../utils/web/isMobile.js";
import { openWindow } from "../../utils/web/openWindow.js";
import { getWalletInfo } from "../__generated__/getWalletInfo.js";
Expand Down Expand Up @@ -374,10 +373,12 @@ function createAccount(provider: WCProvider, address: string) {
// as we can't statically check this with TypeScript.
validateTypedData({ domain, message, primaryType, types });

const typedData = stringify(
{ domain: domain ?? {}, message, primaryType, types },
(_, value) => (isHex(value) ? value.toLowerCase() : value),
);
const typedData = serializeTypedData({
domain: domain ?? {},
message,
primaryType,
types,
});

return await provider.request({
method: "eth_signTypedData_v4",
Expand Down

0 comments on commit e030281

Please sign in to comment.