Skip to content

Commit c5acbff

Browse files
committed
test(sdk): parse-typed-data
1 parent e2754df commit c5acbff

File tree

9 files changed

+63
-7
lines changed

9 files changed

+63
-7
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { describe, expect, test } from "vitest";
2+
import { parseTypedData } from "./parse-typed-data.js";
3+
4+
describe("parseTypedData", () => {
5+
test("parses typed data with hex chainId", () => {
6+
const typedData = {
7+
domain: {
8+
chainId: "0x1" as unknown as number,
9+
},
10+
types: {},
11+
primaryType: "EIP712Domain" as const,
12+
};
13+
14+
const result = parseTypedData(typedData);
15+
expect(result.domain.chainId).toBe(1);
16+
});
17+
18+
test("returns typed data unchanged if chainId is not hex", () => {
19+
const typedData = {
20+
domain: {
21+
chainId: 1,
22+
},
23+
types: {},
24+
primaryType: "EIP712Domain" as const,
25+
};
26+
27+
const result = parseTypedData(typedData);
28+
expect(result.domain.chainId).toBe(1);
29+
});
30+
31+
test("returns typed data unchanged if chainId is undefined", () => {
32+
const typedData = {
33+
domain: {},
34+
types: {},
35+
primaryType: "EIP712Domain" as const,
36+
};
37+
38+
const result = parseTypedData(typedData);
39+
expect(result.domain.chainId).toBeUndefined();
40+
});
41+
42+
test("handles unknown domain properties", () => {
43+
const typedData = {
44+
domain: {
45+
chainId: "0x1" as unknown as number,
46+
name: "Test",
47+
},
48+
types: {},
49+
primaryType: "EIP712Domain" as const,
50+
};
51+
52+
const result = parseTypedData(typedData);
53+
expect(result.domain.chainId).toBe(1);
54+
expect(result.domain.name).toBe("Test");
55+
});
56+
});

packages/thirdweb/src/utils/signatures/sign-typed-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { TypedData } from "abitype";
22
import { type TypedDataDefinition, hashTypedData } from "viem";
33
import type { Hex } from "../encoding/hex.js";
4-
import { parseTypedData } from "./helpers/parseTypedData.js";
4+
import { parseTypedData } from "./helpers/parse-typed-data.js";
55
import { sign } from "./sign.js";
66
import { signatureToHex } from "./signature-to-hex.js";
77

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
stringToHex,
2626
uint8ArrayToHex,
2727
} from "../../utils/encoding/hex.js";
28-
import { parseTypedData } from "../../utils/signatures/helpers/parseTypedData.js";
28+
import { parseTypedData } from "../../utils/signatures/helpers/parse-typed-data.js";
2929
import { COINBASE } from "../constants.js";
3030
import type {
3131
GetCallsStatusResponse,

packages/thirdweb/src/wallets/in-app/core/wallet/enclave-wallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { eth_sendRawTransaction } from "../../../../rpc/actions/eth_sendRawTrans
66
import { getRpcClient } from "../../../../rpc/rpc.js";
77
import { getAddress } from "../../../../utils/address.js";
88
import { type Hex, toHex } from "../../../../utils/encoding/hex.js";
9-
import { parseTypedData } from "../../../../utils/signatures/helpers/parseTypedData.js";
9+
import { parseTypedData } from "../../../../utils/signatures/helpers/parse-typed-data.js";
1010
import type { Prettify } from "../../../../utils/type-utils.js";
1111
import type {
1212
Account,

packages/thirdweb/src/wallets/in-app/web/lib/iframe-wallet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { getRpcClient } from "../../../../rpc/rpc.js";
88
import { getAddress } from "../../../../utils/address.js";
99
import { getThirdwebDomains } from "../../../../utils/domains.js";
1010
import { type Hex, hexToString } from "../../../../utils/encoding/hex.js";
11-
import { parseTypedData } from "../../../../utils/signatures/helpers/parseTypedData.js";
11+
import { parseTypedData } from "../../../../utils/signatures/helpers/parse-typed-data.js";
1212
import type { Prettify } from "../../../../utils/type-utils.js";
1313
import type {
1414
Account,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
stringToHex,
1717
uint8ArrayToHex,
1818
} from "../../utils/encoding/hex.js";
19-
import { parseTypedData } from "../../utils/signatures/helpers/parseTypedData.js";
19+
import { parseTypedData } from "../../utils/signatures/helpers/parse-typed-data.js";
2020
import type { InjectedSupportedWalletIds } from "../__generated__/wallet-ids.js";
2121
import type { Account, SendTransactionOption } from "../interfaces/wallet.js";
2222
import type { DisconnectFn, SwitchChainFn } from "../types.js";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { getAddress } from "../../utils/address.js";
2424
import { isZkSyncChain } from "../../utils/any-evm/zksync/isZkSyncChain.js";
2525
import { concatHex } from "../../utils/encoding/helpers/concat-hex.js";
2626
import type { Hex } from "../../utils/encoding/hex.js";
27-
import { parseTypedData } from "../../utils/signatures/helpers/parseTypedData.js";
27+
import { parseTypedData } from "../../utils/signatures/helpers/parse-typed-data.js";
2828
import type {
2929
Account,
3030
SendTransactionOption,

packages/thirdweb/src/wallets/wallet-connect/controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
uint8ArrayToHex,
2626
} from "../../utils/encoding/hex.js";
2727
import { stringify } from "../../utils/json.js";
28-
import { parseTypedData } from "../../utils/signatures/helpers/parseTypedData.js";
28+
import { parseTypedData } from "../../utils/signatures/helpers/parse-typed-data.js";
2929
import type { AsyncStorage } from "../../utils/storage/AsyncStorage.js";
3030
import {
3131
getSavedConnectParamsFromStorage,

0 commit comments

Comments
 (0)