Skip to content

Commit 73fd7f9

Browse files
committed
fix build
1 parent 7ba458a commit 73fd7f9

File tree

7 files changed

+59
-68
lines changed

7 files changed

+59
-68
lines changed

packages/thirdweb/src/extensions/erc1271/checkContractWalletSignedTypedData.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type TypedData, type TypedDataDefinition, hashTypedData } from "viem";
1+
import * as ox__TypedData from "ox/TypedData";
22
import type { ThirdwebContract } from "../../contract/contract.js";
33
import { isHex } from "../../utils/encoding/hex.js";
44
import { isValidSignature } from "./__generated__/isValidSignature/read/isValidSignature.js";
@@ -7,11 +7,11 @@ import { isValidSignature } from "./__generated__/isValidSignature/read/isValidS
77
* @extension ERC1271
88
*/
99
export type CheckContractWalletSignTypedDataOptions<
10-
typedData extends TypedData | Record<string, unknown>,
10+
typedData extends ox__TypedData.TypedData | Record<string, unknown>,
1111
primaryType extends keyof typedData | "EIP712Domain" = keyof typedData,
1212
> = {
1313
contract: ThirdwebContract;
14-
data: TypedDataDefinition<typedData, primaryType>;
14+
data: ox__TypedData.Definition<typedData, primaryType>;
1515
signature: string;
1616
};
1717
const MAGIC_VALUE = "0x1626ba7e";
@@ -42,15 +42,19 @@ const MAGIC_VALUE = "0x1626ba7e";
4242
* @returns A promise that resolves with a boolean indicating if the signature is valid.
4343
*/
4444
export async function checkContractWalletSignedTypedData<
45-
typedData extends TypedData | Record<string, unknown>,
45+
typedData extends ox__TypedData.TypedData | Record<string, unknown>,
4646
primaryType extends keyof typedData | "EIP712Domain" = keyof typedData,
4747
>(options: CheckContractWalletSignTypedDataOptions<typedData, primaryType>) {
4848
if (!isHex(options.signature)) {
4949
throw new Error("The signature must be a valid hex string.");
5050
}
5151
const result = await isValidSignature({
5252
contract: options.contract,
53-
hash: hashTypedData(options.data),
53+
hash: ox__TypedData.hashStruct({
54+
primaryType: options.data.primaryType,
55+
data: options.data.message as Record<string, unknown>,
56+
types: options.data.types as ox__TypedData.Definition["types"],
57+
}),
5458
signature: options.signature,
5559
});
5660
return result === MAGIC_VALUE;
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
import type { TypedData } from "abitype";
2-
import type { TypedDataDefinition } from "viem";
3-
import { type Hex, hexToNumber, isHex } from "../../encoding/hex.js";
1+
import * as ox__Hex from "ox/Hex";
2+
import type * as ox__TypedData from "ox/TypedData";
3+
import type { Hex } from "../../encoding/hex.js";
44

5-
type UnknownDomain = unknown & { chainId?: unknown }; // TODO: create our own typed data types so this is cleaner
6-
type HexDomain = unknown & { chainId: Hex }; // TODO: create our own typed data types so this is cleaner
5+
type UnknownDomain = unknown & { chainId?: unknown };
6+
type HexDomain = unknown & { chainId: Hex };
77

88
/**
99
* @internal
1010
*/
1111
export function parseTypedData<
12-
typedData extends TypedData | Record<string, unknown> = TypedData,
12+
typedData extends
13+
| ox__TypedData.TypedData
14+
| Record<string, unknown> = ox__TypedData.TypedData,
1315
primaryType extends keyof typedData | "EIP712Domain" = keyof typedData,
1416
>(
15-
typedData: TypedDataDefinition<typedData, primaryType>,
16-
): TypedDataDefinition<typedData, primaryType> {
17+
typedData: ox__TypedData.Definition<typedData, primaryType>,
18+
): ox__TypedData.Definition<typedData, primaryType> {
1719
const domain = typedData.domain as UnknownDomain;
18-
if (domain?.chainId !== undefined && isHex(domain.chainId)) {
20+
if (domain?.chainId !== undefined && ox__Hex.validate(domain.chainId)) {
1921
typedData.domain = {
2022
...(typedData.domain as HexDomain),
21-
chainId: hexToNumber((typedData.domain as unknown as HexDomain).chainId),
22-
} as unknown as TypedDataDefinition<typedData, primaryType>["domain"];
23+
chainId: ox__Hex.toNumber(
24+
(typedData.domain as unknown as HexDomain).chainId,
25+
),
26+
} as unknown as ox__TypedData.Definition<typedData, primaryType>["domain"];
2327
}
2428
return typedData;
2529
}

packages/thirdweb/src/wallets/coinbase/coinbaseWebSDK.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import type { ProviderInterface } from "@coinbase/wallet-sdk";
22
import type { Address } from "abitype";
3-
import {
4-
type SignTypedDataParameters,
5-
getTypesForEIP712Domain,
6-
isHex,
7-
serializeTypedData,
8-
validateTypedData,
9-
} from "viem";
3+
import * as ox__Hex from "ox/Hex";
4+
import * as ox__TypedData from "ox/TypedData";
105
import type { Account, Wallet } from "../interfaces/wallet.js";
116
import type { SendTransactionOption } from "../interfaces/wallet.js";
127
import type { AppMetadata, DisconnectFn, SwitchChainFn } from "../types.js";
@@ -338,29 +333,30 @@ function createAccount({
338333
method: "personal_sign",
339334
params: [messageToSign, account.address],
340335
});
341-
if (!isHex(res)) {
336+
if (!ox__Hex.validate(res)) {
342337
throw new Error("Invalid signature returned");
343338
}
344339
return res;
345340
},
346-
async signTypedData(_typedData) {
341+
async signTypedData(typedData) {
347342
if (!account.address) {
348343
throw new Error("Provider not setup");
349344
}
350-
const typedData = parseTypedData(_typedData);
351-
const { domain, message, primaryType } =
352-
typedData as unknown as SignTypedDataParameters;
345+
346+
const { domain, message, primaryType } = parseTypedData(
347+
typedData,
348+
) as ox__TypedData.Definition;
353349

354350
const types = {
355-
EIP712Domain: getTypesForEIP712Domain({ domain }),
351+
EIP712Domain: ox__TypedData.extractEip712DomainTypes(domain),
356352
...typedData.types,
357353
};
358354

359355
// Need to do a runtime validation check on addresses, byte ranges, integer ranges, etc
360356
// as we can't statically check this with TypeScript.
361-
validateTypedData({ domain, message, primaryType, types });
357+
ox__TypedData.validate({ domain, message, primaryType, types });
362358

363-
const stringifiedData = serializeTypedData({
359+
const stringifiedData = ox__TypedData.serialize({
364360
domain: domain ?? {},
365361
message,
366362
primaryType,
@@ -371,7 +367,7 @@ function createAccount({
371367
method: "eth_signTypedData_v4",
372368
params: [account.address, stringifiedData],
373369
});
374-
if (!isHex(res)) {
370+
if (!ox__Hex.validate(res)) {
375371
throw new Error("Invalid signed payload returned");
376372
}
377373
return res;

packages/thirdweb/src/wallets/in-app/core/actions/sign-typed-data.enclave.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
import type { TypedData } from "abitype";
2-
import type { TypedDataDefinition } from "viem";
1+
import type * as ox__TypedData from "ox/TypedData";
32
import type { ThirdwebClient } from "../../../../client/client.js";
43
import { getThirdwebBaseUrl } from "../../../../utils/domains.js";
54
import { getClientFetch } from "../../../../utils/fetch.js";
65
import { stringify } from "../../../../utils/json.js";
76
import type { ClientScopedStorage } from "../authentication/client-scoped-storage.js";
87

98
export async function signTypedData<
10-
const typedData extends TypedData | Record<string, unknown>,
9+
const typedData extends ox__TypedData.TypedData | Record<string, unknown>,
1110
primaryType extends keyof typedData | "EIP712Domain" = keyof typedData,
1211
>({
1312
client,
1413
payload,
1514
storage,
1615
}: {
1716
client: ThirdwebClient;
18-
payload: TypedDataDefinition<typedData, primaryType>;
17+
payload: ox__TypedData.Definition<typedData, primaryType>;
1918
storage: ClientScopedStorage;
2019
}) {
2120
const authToken = await storage.getAuthCookie();

packages/thirdweb/src/wallets/interfaces/wallet.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import type { Address } from "abitype";
2-
import type {
3-
Hex,
4-
SignableMessage,
5-
TransactionSerializable,
6-
TypedData,
7-
TypedDataDefinition,
8-
} from "viem";
2+
import type * as ox__TypedData from "ox/TypedData";
3+
import type { Hex, SignableMessage, TransactionSerializable } from "viem";
94
import type { Chain } from "../../chains/types.js";
105
import type {
116
EIP712TransactionOptions,
@@ -191,10 +186,10 @@ export type Account = {
191186
* ```
192187
*/
193188
signTypedData: <
194-
const typedData extends TypedData | Record<string, unknown>,
189+
const typedData extends ox__TypedData.TypedData | Record<string, unknown>,
195190
primaryType extends keyof typedData | "EIP712Domain" = keyof typedData,
196191
>(
197-
_typedData: TypedDataDefinition<typedData, primaryType>,
192+
_typedData: ox__TypedData.Definition<typedData, primaryType>,
198193
) => Promise<Hex>;
199194

200195
// OPTIONAL

packages/thirdweb/src/wallets/private-key.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { secp256k1 } from "@noble/curves/secp256k1";
2-
import type {
3-
SignableMessage,
4-
TransactionSerializable,
5-
TypedData,
6-
TypedDataDefinition,
7-
} from "viem";
2+
import type * as ox__TypedData from "ox/TypedData";
3+
import type { SignableMessage, TransactionSerializable } from "viem";
84
import { publicKeyToAddress } from "viem/utils";
95
import { getCachedChain } from "../chains/utils.js";
106
import type { ThirdwebClient } from "../client/client.js";
@@ -99,10 +95,10 @@ export function privateKeyToAccount(
9995
});
10096
},
10197
signTypedData: async <
102-
const typedData extends TypedData | Record<string, unknown>,
98+
const typedData extends ox__TypedData.TypedData | Record<string, unknown>,
10399
primaryType extends keyof typedData | "EIP712Domain" = keyof typedData,
104100
>(
105-
_typedData: TypedDataDefinition<typedData, primaryType>,
101+
_typedData: ox__TypedData.Definition<typedData, primaryType>,
106102
) => {
107103
return signTypedData({
108104
..._typedData,

packages/thirdweb/src/wallets/smart/index.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
import {
2-
type SignableMessage,
3-
type TypedData,
4-
type TypedDataDefinition,
5-
type TypedDataDomain,
6-
hashTypedData,
7-
maxUint96,
8-
} from "viem";
1+
import * as ox__TypedData from "ox/TypedData";
2+
import { type SignableMessage, maxUint96 } from "viem";
93
import type { Chain } from "../../chains/types.js";
104
import { getCachedChain } from "../../chains/utils.js";
115
import type { ThirdwebClient } from "../../client/client.js";
@@ -140,7 +134,6 @@ export async function connectSmartWallet(
140134
chain: chain,
141135
});
142136

143-
// TODO: listen for chainChanged event on the personal wallet and emit the disconnect event on the smart wallet
144137
const accountAddress = await predictAddress({
145138
factoryContract,
146139
adminAddress: personalAccount.address,
@@ -334,9 +327,9 @@ async function createSmartAccount(
334327
);
335328
},
336329
async signTypedData<
337-
const typedData extends TypedData | Record<string, unknown>,
330+
const typedData extends ox__TypedData.TypedData | Record<string, unknown>,
338331
primaryType extends keyof typedData | "EIP712Domain" = keyof typedData,
339-
>(_typedData: TypedDataDefinition<typedData, primaryType>) {
332+
>(_typedData: ox__TypedData.Definition<typedData, primaryType>) {
340333
const typedData = parseTypedData(_typedData);
341334
const [
342335
{ isContractDeployed },
@@ -353,7 +346,7 @@ async function createSmartAccount(
353346
]);
354347
const isSelfVerifyingContract =
355348
(
356-
typedData.domain as TypedDataDomain
349+
typedData.domain as ox__TypedData.Domain
357350
)?.verifyingContract?.toLowerCase() ===
358351
accountContract.address?.toLowerCase();
359352

@@ -376,7 +369,11 @@ async function createSmartAccount(
376369
});
377370
}
378371

379-
const originalMsgHash = hashTypedData(typedData);
372+
const originalMsgHash = ox__TypedData.hashStruct({
373+
...typedData,
374+
types: typedData.types as ox__TypedData.Definition["types"],
375+
data: typedData.message as Record<string, unknown>,
376+
});
380377
// check if the account contract supports EIP721 domain separator based signing
381378
let factorySupports712 = false;
382379
try {
@@ -554,9 +551,9 @@ function createZkSyncAccount(args: {
554551
return connectionOptions.personalAccount.signMessage({ message });
555552
},
556553
async signTypedData<
557-
const typedData extends TypedData | Record<string, unknown>,
554+
const typedData extends ox__TypedData.TypedData | Record<string, unknown>,
558555
primaryType extends keyof typedData | "EIP712Domain" = keyof typedData,
559-
>(_typedData: TypedDataDefinition<typedData, primaryType>) {
556+
>(_typedData: ox__TypedData.Definition<typedData, primaryType>) {
560557
const typedData = parseTypedData(_typedData);
561558
return connectionOptions.personalAccount.signTypedData(typedData);
562559
},

0 commit comments

Comments
 (0)