Skip to content

Commit 7a3ab24

Browse files
fix: use stringify helper for bigint serialization
1 parent f40d247 commit 7a3ab24

File tree

32 files changed

+89
-58
lines changed

32 files changed

+89
-58
lines changed

.changeset/dull-mails-sleep.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Use stringify instead of JSON.stringify in most places to handle bigint serialization

packages/thirdweb/src/auth/core/verify-jwt.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { stringify } from "../../utils/json.js";
12
import { decodeJWT } from "../../utils/jwt/decode-jwt.js";
23
import type { JWTPayload } from "../../utils/jwt/types.js";
34
import { verifyEOASignature } from "../verify-signature.js";
@@ -82,7 +83,7 @@ export function verifyJWT(options: AuthOptions) {
8283
}
8384

8485
const verified = await verifyEOASignature({
85-
message: JSON.stringify(payload),
86+
message: stringify(payload),
8687
signature,
8788
address: issuerAddress,
8889
});

packages/thirdweb/src/pay/buyWithCrypto/getQuote.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
QuoteTokenInfo,
1313
QuoteTransactionRequest,
1414
} from "./commonTypes.js";
15+
import { stringify } from "../../utils/json.js";
1516

1617
/**
1718
* The parameters for [`getBuyWithCryptoQuote`](https://portal.thirdweb.com/references/typescript/v5/getBuyWithCryptoQuote) function
@@ -223,7 +224,7 @@ export async function getBuyWithCryptoQuote(
223224
Accept: "application/json",
224225
"Content-Type": "application/json",
225226
},
226-
body: JSON.stringify({
227+
body: stringify({
227228
fromAddress: params.fromAddress,
228229
toAddress: params.toAddress,
229230
fromChainId: params.fromChainId.toString(),

packages/thirdweb/src/pay/buyWithCrypto/getTransfer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
QuoteTokenInfo,
1414
QuoteTransactionRequest,
1515
} from "./commonTypes.js";
16+
import { stringify } from "../../utils/json.js";
1617

1718
/**
1819
* The parameters for [`getBuyWithCryptoTransfer`](https://portal.thirdweb.com/references/typescript/v5/getBuyWithCryptoTransfer) function
@@ -129,7 +130,7 @@ export async function getBuyWithCryptoTransfer(
129130
Accept: "application/json",
130131
"Content-Type": "application/json",
131132
},
132-
body: JSON.stringify({
133+
body: stringify({
133134
fromAddress: params.fromAddress,
134135
toAddress: params.toAddress,
135136
chainId: params.chainId,

packages/thirdweb/src/pay/buyWithFiat/getQuote.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ThirdwebClient } from "../../client/client.js";
22
import { getClientFetch } from "../../utils/fetch.js";
3+
import { stringify } from "../../utils/json.js";
34
import type { FiatProvider } from "../utils/commonTypes.js";
45
import { getPayBuyWithFiatQuoteEndpoint } from "../utils/definitions.js";
56

@@ -299,7 +300,7 @@ export async function getBuyWithFiatQuote(
299300
Accept: "application/json",
300301
"Content-Type": "application/json",
301302
},
302-
body: JSON.stringify({
303+
body: stringify({
303304
toAddress: params.toAddress,
304305
fromCurrencySymbol: params.fromCurrencySymbol,
305306
toChainId: params.toChainId.toString(),

packages/thirdweb/src/rpc/rpc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ThirdwebClient } from "../client/client.js";
33

44
import type { Chain } from "../chains/types.js";
55
import { getRpcUrlForChain } from "../chains/utils.js";
6+
import { stringify } from "../utils/json.js";
67
import { type RpcRequest, fetchRpc, fetchSingleRpc } from "./fetch-rpc.js";
78

89
const RPC_CLIENT_MAP = new WeakMap();
@@ -23,7 +24,7 @@ function getRpcClientMap(client: ThirdwebClient) {
2324
* @internal
2425
*/
2526
function rpcRequestKey(request: RpcRequest): string {
26-
return `${request.method}:${JSON.stringify(request.params)}`;
27+
return `${request.method}:${stringify(request.params)}`;
2728
}
2829

2930
const DEFAULT_MAX_BATCH_SIZE = 100;

packages/thirdweb/src/utils/extensions/airdrop/process-snapshot-erc1155.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ThirdwebClient } from "../../../client/client.js";
22
import { MerkleTree } from "../../../merkletree/MerkleTree.js";
33
import { upload } from "../../../storage/upload.js";
44
import type { Hex } from "../../encoding/hex.js";
5+
import { stringify } from "../../json.js";
56
import { hashEntryERC1155 } from "./hash-entry-erc1155.js";
67
import type {
78
ShardDataERC1155,
@@ -54,7 +55,7 @@ export async function processSnapshotERC1155(options: {
5455
entries,
5556
};
5657
shardsToUpload.push({
57-
data: JSON.stringify(data),
58+
data: stringify(data),
5859
name: `${shardId}.json`,
5960
});
6061
}
@@ -74,7 +75,7 @@ export async function processSnapshotERC1155(options: {
7475
// 6. Also upload the original entries for retrieving all entries
7576
const originalEntriesUri = await upload({
7677
client: options.client,
77-
files: [JSON.stringify(options.snapshot)],
78+
files: [stringify(options.snapshot)],
7879
});
7980
// 7. assmeble the final sharded merkle tree info
8081
const shardedMerkleInfo: ShardedMerkleTreeInfo = {

packages/thirdweb/src/utils/extensions/airdrop/process-snapshot-erc20.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ThirdwebClient } from "../../../client/client.js";
22
import { MerkleTree } from "../../../merkletree/MerkleTree.js";
33
import { upload } from "../../../storage/upload.js";
44
import type { Hex } from "../../encoding/hex.js";
5+
import { stringify } from "../../json.js";
56
import { hashEntryERC20 } from "./hash-entry-erc20.js";
67
import type {
78
ShardDataERC20,
@@ -56,7 +57,7 @@ export async function processSnapshotERC20(options: {
5657
entries,
5758
};
5859
shardsToUpload.push({
59-
data: JSON.stringify(data),
60+
data: stringify(data),
6061
name: `${shardId}.json`,
6162
});
6263
}
@@ -76,7 +77,7 @@ export async function processSnapshotERC20(options: {
7677
// 6. Also upload the original entries for retrieving all entries
7778
const originalEntriesUri = await upload({
7879
client: options.client,
79-
files: [JSON.stringify(options.snapshot)],
80+
files: [stringify(options.snapshot)],
8081
});
8182
// 7. assmeble the final sharded merkle tree info
8283
const shardedMerkleInfo: ShardedMerkleTreeInfo = {

packages/thirdweb/src/utils/extensions/airdrop/process-snapshot-erc721.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ThirdwebClient } from "../../../client/client.js";
22
import { MerkleTree } from "../../../merkletree/MerkleTree.js";
33
import { upload } from "../../../storage/upload.js";
44
import type { Hex } from "../../encoding/hex.js";
5+
import { stringify } from "../../json.js";
56
import { hashEntryERC721 } from "./hash-entry-erc721.js";
67
import type {
78
ShardDataERC721,
@@ -54,7 +55,7 @@ export async function processSnapshotERC721(options: {
5455
entries,
5556
};
5657
shardsToUpload.push({
57-
data: JSON.stringify(data),
58+
data: stringify(data),
5859
name: `${shardId}.json`,
5960
});
6061
}
@@ -74,7 +75,7 @@ export async function processSnapshotERC721(options: {
7475
// 6. Also upload the original entries for retrieving all entries
7576
const originalEntriesUri = await upload({
7677
client: options.client,
77-
files: [JSON.stringify(options.snapshot)],
78+
files: [stringify(options.snapshot)],
7879
});
7980
// 7. assmeble the final sharded merkle tree info
8081
const shardedMerkleInfo: ShardedMerkleTreeInfo = {

packages/thirdweb/src/utils/extensions/drops/process-override-list.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ThirdwebClient } from "../../../client/client.js";
33
import { MerkleTree } from "../../../merkletree/MerkleTree.js";
44
import { upload } from "../../../storage/upload.js";
55
import type { Hex } from "../../encoding/hex.js";
6+
import { stringify } from "../../json.js";
67
import { hashEntry } from "./hash-entry.js";
78
import type {
89
OverrideEntry,
@@ -67,7 +68,7 @@ export async function processOverrideList(options: {
6768
entries,
6869
};
6970
shardsToUpload.push({
70-
data: JSON.stringify(data),
71+
data: stringify(data),
7172
name: `${shardId}.json`,
7273
});
7374
}
@@ -87,7 +88,7 @@ export async function processOverrideList(options: {
8788
// 6. Also upload the original entries for retrieving all entries
8889
const originalEntriesUri = await upload({
8990
client: options.client,
90-
files: [JSON.stringify(options.overrides)],
91+
files: [stringify(options.overrides)],
9192
});
9293
// 7. assmeble the final sharded merkle tree info
9394
const shardedMerkleInfo: ShardedMerkleTreeInfo = {

0 commit comments

Comments
 (0)