From e030281a6a683f5664ac70985b462a6458c5b39e Mon Sep 17 00:00:00 2001 From: jxom Date: Thu, 6 Jun 2024 17:20:23 +1000 Subject: [PATCH] fix: resolves https://github.com/wevm/viem/issues/2306 --- packages/thirdweb/package.json | 4 ++-- .../src/wallets/coinbase/coinbaseSDKWallet.ts | 13 +++++++------ packages/thirdweb/src/wallets/injected/index.ts | 13 +++++++------ .../src/wallets/wallet-connect/controller.ts | 13 +++++++------ 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/packages/thirdweb/package.json b/packages/thirdweb/package.json index e86c6cb6091..60ba3f02796 100644 --- a/packages/thirdweb/package.json +++ b/packages/thirdweb/package.json @@ -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", @@ -310,4 +310,4 @@ "shamir-secret-sharing": "0.0.3", "vitest": "1.5.0" } -} +} \ No newline at end of file diff --git a/packages/thirdweb/src/wallets/coinbase/coinbaseSDKWallet.ts b/packages/thirdweb/src/wallets/coinbase/coinbaseSDKWallet.ts index 437b15cc128..36cdfab1a94 100644 --- a/packages/thirdweb/src/wallets/coinbase/coinbaseSDKWallet.ts +++ b/packages/thirdweb/src/wallets/coinbase/coinbaseSDKWallet.ts @@ -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"; @@ -22,7 +22,6 @@ import type { ThirdwebClient } from "../../client/client.js"; import { getAddress } from "../../utils/address.js"; import { type Hex, - isHex, numberToHex, stringToHex, uint8ArrayToHex, @@ -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", diff --git a/packages/thirdweb/src/wallets/injected/index.ts b/packages/thirdweb/src/wallets/injected/index.ts index 8e3478b4d1a..13e19ac739a 100644 --- a/packages/thirdweb/src/wallets/injected/index.ts +++ b/packages/thirdweb/src/wallets/injected/index.ts @@ -2,6 +2,7 @@ import type { Address } from "abitype"; import { type SignTypedDataParameters, getTypesForEIP712Domain, + serializeTypedData, validateTypedData, } from "viem"; import type { Chain } from "../../chains/types.js"; @@ -9,12 +10,10 @@ 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, @@ -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", diff --git a/packages/thirdweb/src/wallets/wallet-connect/controller.ts b/packages/thirdweb/src/wallets/wallet-connect/controller.ts index cac65ca079d..9170b272937 100644 --- a/packages/thirdweb/src/wallets/wallet-connect/controller.ts +++ b/packages/thirdweb/src/wallets/wallet-connect/controller.ts @@ -6,6 +6,7 @@ import { SwitchChainError, UserRejectedRequestError, getTypesForEIP712Domain, + serializeTypedData, validateTypedData, } from "viem"; import type { Chain } from "../../chains/types.js"; @@ -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"; @@ -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",