Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dull-mails-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Use stringify instead of JSON.stringify in most places to handle bigint serialization
3 changes: 2 additions & 1 deletion packages/thirdweb/src/auth/core/verify-jwt.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { stringify } from "../../utils/json.js";
import { decodeJWT } from "../../utils/jwt/decode-jwt.js";
import type { JWTPayload } from "../../utils/jwt/types.js";
import { verifyEOASignature } from "../verify-signature.js";
Expand Down Expand Up @@ -82,7 +83,7 @@ export function verifyJWT(options: AuthOptions) {
}

const verified = await verifyEOASignature({
message: JSON.stringify(payload),
message: stringify(payload),
signature,
address: issuerAddress,
});
Expand Down
3 changes: 2 additions & 1 deletion packages/thirdweb/src/pay/buyWithCrypto/getQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { approve } from "../../extensions/erc20/write/approve.js";
import type { PrepareTransactionOptions } from "../../transaction/prepare-transaction.js";
import { getClientFetch } from "../../utils/fetch.js";
import { stringify } from "../../utils/json.js";
import { getPayBuyWithCryptoQuoteEndpoint } from "../utils/definitions.js";
import type {
QuoteApprovalInfo,
Expand Down Expand Up @@ -223,7 +224,7 @@
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
body: stringify({

Check warning on line 227 in packages/thirdweb/src/pay/buyWithCrypto/getQuote.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L227 was not covered by tests
fromAddress: params.fromAddress,
toAddress: params.toAddress,
fromChainId: params.fromChainId.toString(),
Expand Down
3 changes: 2 additions & 1 deletion packages/thirdweb/src/pay/buyWithCrypto/getTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import type { PrepareTransactionOptions } from "../../transaction/prepare-transaction.js";
import type { Address } from "../../utils/address.js";
import { getClientFetch } from "../../utils/fetch.js";
import { stringify } from "../../utils/json.js";
import { getPayBuyWithCryptoTransferEndpoint } from "../utils/definitions.js";
import type {
QuoteApprovalInfo,
Expand Down Expand Up @@ -129,7 +130,7 @@
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
body: stringify({

Check warning on line 133 in packages/thirdweb/src/pay/buyWithCrypto/getTransfer.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L133 was not covered by tests
fromAddress: params.fromAddress,
toAddress: params.toAddress,
chainId: params.chainId,
Expand Down
3 changes: 2 additions & 1 deletion packages/thirdweb/src/pay/buyWithFiat/getQuote.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ThirdwebClient } from "../../client/client.js";
import { getClientFetch } from "../../utils/fetch.js";
import { stringify } from "../../utils/json.js";
import type { FiatProvider } from "../utils/commonTypes.js";
import { getPayBuyWithFiatQuoteEndpoint } from "../utils/definitions.js";

Expand Down Expand Up @@ -299,7 +300,7 @@
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
body: stringify({

Check warning on line 303 in packages/thirdweb/src/pay/buyWithFiat/getQuote.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L303 was not covered by tests
toAddress: params.toAddress,
fromCurrencySymbol: params.fromCurrencySymbol,
toChainId: params.toChainId.toString(),
Expand Down
3 changes: 2 additions & 1 deletion packages/thirdweb/src/rpc/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ThirdwebClient } from "../client/client.js";

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

const RPC_CLIENT_MAP = new WeakMap();
Expand All @@ -23,7 +24,7 @@ function getRpcClientMap(client: ThirdwebClient) {
* @internal
*/
function rpcRequestKey(request: RpcRequest): string {
return `${request.method}:${JSON.stringify(request.params)}`;
return `${request.method}:${stringify(request.params)}`;
}

const DEFAULT_MAX_BATCH_SIZE = 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ThirdwebClient } from "../../../client/client.js";
import { MerkleTree } from "../../../merkletree/MerkleTree.js";
import { upload } from "../../../storage/upload.js";
import type { Hex } from "../../encoding/hex.js";
import { stringify } from "../../json.js";
import { hashEntryERC1155 } from "./hash-entry-erc1155.js";
import type {
ShardDataERC1155,
Expand Down Expand Up @@ -54,7 +55,7 @@ export async function processSnapshotERC1155(options: {
entries,
};
shardsToUpload.push({
data: JSON.stringify(data),
data: stringify(data),
name: `${shardId}.json`,
});
}
Expand All @@ -74,7 +75,7 @@ export async function processSnapshotERC1155(options: {
// 6. Also upload the original entries for retrieving all entries
const originalEntriesUri = await upload({
client: options.client,
files: [JSON.stringify(options.snapshot)],
files: [stringify(options.snapshot)],
});
// 7. assmeble the final sharded merkle tree info
const shardedMerkleInfo: ShardedMerkleTreeInfo = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { MerkleTree } from "../../../merkletree/MerkleTree.js";
import { upload } from "../../../storage/upload.js";
import type { Hex } from "../../encoding/hex.js";
import { stringify } from "../../json.js";
import { hashEntryERC20 } from "./hash-entry-erc20.js";
import type {
ShardDataERC20,
Expand Down Expand Up @@ -56,7 +57,7 @@
entries,
};
shardsToUpload.push({
data: JSON.stringify(data),
data: stringify(data),

Check warning on line 60 in packages/thirdweb/src/utils/extensions/airdrop/process-snapshot-erc20.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L60 was not covered by tests
name: `${shardId}.json`,
});
}
Expand All @@ -76,7 +77,7 @@
// 6. Also upload the original entries for retrieving all entries
const originalEntriesUri = await upload({
client: options.client,
files: [JSON.stringify(options.snapshot)],
files: [stringify(options.snapshot)],

Check warning on line 80 in packages/thirdweb/src/utils/extensions/airdrop/process-snapshot-erc20.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L80 was not covered by tests
});
// 7. assmeble the final sharded merkle tree info
const shardedMerkleInfo: ShardedMerkleTreeInfo = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { MerkleTree } from "../../../merkletree/MerkleTree.js";
import { upload } from "../../../storage/upload.js";
import type { Hex } from "../../encoding/hex.js";
import { stringify } from "../../json.js";
import { hashEntryERC721 } from "./hash-entry-erc721.js";
import type {
ShardDataERC721,
Expand Down Expand Up @@ -54,7 +55,7 @@
entries,
};
shardsToUpload.push({
data: JSON.stringify(data),
data: stringify(data),

Check warning on line 58 in packages/thirdweb/src/utils/extensions/airdrop/process-snapshot-erc721.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L58 was not covered by tests
name: `${shardId}.json`,
});
}
Expand All @@ -74,7 +75,7 @@
// 6. Also upload the original entries for retrieving all entries
const originalEntriesUri = await upload({
client: options.client,
files: [JSON.stringify(options.snapshot)],
files: [stringify(options.snapshot)],

Check warning on line 78 in packages/thirdweb/src/utils/extensions/airdrop/process-snapshot-erc721.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L78 was not covered by tests
});
// 7. assmeble the final sharded merkle tree info
const shardedMerkleInfo: ShardedMerkleTreeInfo = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ThirdwebClient } from "../../../client/client.js";
import { MerkleTree } from "../../../merkletree/MerkleTree.js";
import { upload } from "../../../storage/upload.js";
import type { Hex } from "../../encoding/hex.js";
import { stringify } from "../../json.js";
import { hashEntry } from "./hash-entry.js";
import type {
OverrideEntry,
Expand Down Expand Up @@ -67,7 +68,7 @@ export async function processOverrideList(options: {
entries,
};
shardsToUpload.push({
data: JSON.stringify(data),
data: stringify(data),
name: `${shardId}.json`,
});
}
Expand All @@ -87,7 +88,7 @@ export async function processOverrideList(options: {
// 6. Also upload the original entries for retrieving all entries
const originalEntriesUri = await upload({
client: options.client,
files: [JSON.stringify(options.overrides)],
files: [stringify(options.overrides)],
});
// 7. assmeble the final sharded merkle tree info
const shardedMerkleInfo: ShardedMerkleTreeInfo = {
Expand Down
10 changes: 5 additions & 5 deletions packages/thirdweb/src/utils/jwt/encode-jwt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Account } from "../../wallets/interfaces/wallet.js";
import { stringToBytes } from "../encoding/to-bytes.js";
import { stringify } from "../json.js";
import { randomBytesHex } from "../random.js";
import { uint8ArrayToBase64 } from "../uint8-array.js";
import { PRECOMPILED_B64_ENCODED_JWT_HEADER } from "./jwt-header.js";
Expand Down Expand Up @@ -47,14 +48,13 @@ type EncodeJWTParams = { payload: JWTPayloadInput; account: Account };
*/
export async function encodeJWT(options: EncodeJWTParams) {
const payload = await ensureJWTPayload(options.payload);
const message = JSON.stringify(payload);
const message = stringify(payload);

const signature = await options.account.signMessage({ message });

const encodedData = uint8ArrayToBase64(
stringToBytes(JSON.stringify(payload)),
{ urlSafe: true },
);
const encodedData = uint8ArrayToBase64(stringToBytes(message), {
urlSafe: true,
});

const encodedSignature = uint8ArrayToBase64(stringToBytes(signature), {
urlSafe: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it } from "vitest";
import { TEST_CLIENT } from "~test/test-clients.js";
import { stringify } from "../json.js";
import {
type FetchTokenMetadataOptions,
fetchTokenMetadata,
Expand All @@ -9,7 +10,7 @@ describe("fetchTokenMetadata", () => {
it("should return a json object from a valid base64 encoded json", async () => {
const validJson = { foo: "bar" };
const validBase64Json = `data:application/json;base64,${btoa(
JSON.stringify(validJson),
stringify(validJson),
)}`;

const options: FetchTokenMetadataOptions = {
Expand Down
7 changes: 4 additions & 3 deletions packages/thirdweb/src/utils/storage/walletStorage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { stringify } from "../json.js";
import type { AsyncStorage } from "./AsyncStorage.js";

const CONNECT_PARAMS_MAP_KEY = "tw:connected-wallet-params";
Expand Down Expand Up @@ -39,7 +40,7 @@
};
}

storage.setItem(CONNECT_PARAMS_MAP_KEY, JSON.stringify(value));
storage.setItem(CONNECT_PARAMS_MAP_KEY, stringify(value));

Check warning on line 43 in packages/thirdweb/src/utils/storage/walletStorage.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/utils/storage/walletStorage.ts#L43

Added line #L43 was not covered by tests
}

/**
Expand Down Expand Up @@ -67,7 +68,7 @@
}

delete value[walletId];
storage.setItem(CONNECT_PARAMS_MAP_KEY, JSON.stringify(value));
storage.setItem(CONNECT_PARAMS_MAP_KEY, stringify(value));

Check warning on line 71 in packages/thirdweb/src/utils/storage/walletStorage.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/utils/storage/walletStorage.ts#L71

Added line #L71 was not covered by tests
}
}

Expand Down Expand Up @@ -100,7 +101,7 @@

function isStringifiable(value: unknown): boolean {
try {
JSON.stringify(value);
stringify(value);

Check warning on line 104 in packages/thirdweb/src/utils/storage/walletStorage.ts

View check run for this annotation

Codecov / codecov/patch

packages/thirdweb/src/utils/storage/walletStorage.ts#L104

Added line #L104 was not covered by tests
return true;
} catch {
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ThirdwebClient } from "../../../../client/client.js";
import { getClientFetch } from "../../../../utils/fetch.js";
import { stringify } from "../../../../utils/json.js";
import { ROUTE_AUTH_ENDPOINT_CALLBACK } from "../../native/helpers/constants.js";
import { createErrorMessage } from "../../native/helpers/errors.js";
import type { Ecosystem } from "../wallet/types.js";
Expand All @@ -17,7 +18,7 @@ export async function authEndpoint(args: {
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
body: stringify({
payload: args.payload,
developerClientId: args.client.clientId,
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ThirdwebClient } from "../../../../client/client.js";
import { getClientFetch } from "../../../../utils/fetch.js";
import { stringify } from "../../../../utils/json.js";
import { randomBytesHex } from "../../../../utils/random.js";
import type { AsyncStorage } from "../../../../utils/storage/AsyncStorage.js";
import type { Ecosystem } from "../wallet/types.js";
Expand Down Expand Up @@ -39,7 +40,7 @@ export async function guestAuthenticate(args: {
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
body: stringify({
sessionId,
}),
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ThirdwebClient } from "../../../../client/client.js";
import { getClientFetch } from "../../../../utils/fetch.js";
import { stringify } from "../../../../utils/json.js";
import { ROUTE_AUTH_JWT_CALLBACK } from "../../native/helpers/constants.js";
import { createErrorMessage } from "../../native/helpers/errors.js";
import type { Ecosystem } from "../wallet/types.js";
Expand All @@ -17,7 +18,7 @@ export async function customJwt(args: {
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
body: stringify({
jwt: args.jwt,
developerClientId: args.client.clientId,
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ThirdwebClient } from "../../../../client/client.js";
import { getThirdwebBaseUrl } from "../../../../utils/domains.js";
import { getClientFetch } from "../../../../utils/fetch.js";
import { stringify } from "../../../../utils/json.js";
import type { Ecosystem } from "../wallet/types.js";
import type { ClientScopedStorage } from "./client-scoped-storage.js";
import type { Profile } from "./types.js";
Expand Down Expand Up @@ -40,7 +41,7 @@ export async function linkAccount({
{
method: "POST",
headers,
body: JSON.stringify({
body: stringify({
accountAuthTokenToConnect: tokenToLink,
}),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ThirdwebClient } from "../../../../client/client.js";
import { getThirdwebBaseUrl } from "../../../../utils/domains.js";
import { getClientFetch } from "../../../../utils/fetch.js";
import { stringify } from "../../../../utils/json.js";
import type { Ecosystem } from "../wallet/types.js";
import type { ClientScopedStorage } from "./client-scoped-storage.js";
import type { AuthStoredTokenWithCookieReturnType } from "./types.js";
Expand Down Expand Up @@ -96,7 +97,7 @@ export async function registerPasskey(options: {
"Content-Type": "application/json",
...customHeaders,
},
body: JSON.stringify({
body: stringify({
type: "sign-up",
authenticatorData: registration.authenticatorData,
credentialId: registration.credentialId,
Expand Down Expand Up @@ -166,7 +167,7 @@ export async function loginWithPasskey(options: {
"Content-Type": "application/json",
...customHeaders,
},
body: JSON.stringify({
body: stringify({
type: "sign-in",
authenticatorData: authentication.authenticatorData,
credentialId: authentication.credentialId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { LoginPayload } from "../../../../auth/core/types.js";
import type { Chain } from "../../../../chains/types.js";
import type { ThirdwebClient } from "../../../../client/client.js";
import { getClientFetch } from "../../../../utils/fetch.js";
import { stringify } from "../../../../utils/json.js";
import type { Wallet } from "../../../interfaces/wallet.js";
import type { Ecosystem } from "../wallet/types.js";
import { getLoginCallbackUrl, getLoginUrl } from "./getLoginPath.js";
Expand Down Expand Up @@ -50,7 +51,7 @@ export async function siweAuthenticate(args: {
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
body: stringify({
signature,
payload,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { Chain } from "../../../../chains/types.js";
import { getCachedChainIfExists } from "../../../../chains/utils.js";
import type { ThirdwebClient } from "../../../../client/client.js";
import { stringify } from "../../../../utils/json.js";
import { getEcosystemInfo } from "../../../ecosystem/get-ecosystem-wallet-auth-options.js";
import type { Account, Wallet } from "../../../interfaces/wallet.js";
import { createWalletEmitter } from "../../../wallet-emitter.js";
Expand All @@ -22,7 +23,7 @@
connectorFactory: (client: ThirdwebClient) => Promise<InAppConnector>,
ecosystem?: Ecosystem,
) {
const key = JSON.stringify({ clientId: client.clientId, ecosystem });
const key = stringify({ clientId: client.clientId, ecosystem });

Check warning on line 26 in packages/thirdweb/src/wallets/in-app/core/wallet/in-app-core.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L26 was not covered by tests
if (connectorCache.has(key)) {
return connectorCache.get(key) as InAppConnector;
}
Expand Down
Loading
Loading