Skip to content

Commit 035cb16

Browse files
authored
fix: Enforce Address schema wherever an address is expected (#657)
* fix: Enforce Address schema wherever an address is expected * More instances of string types * fix indentation * format
1 parent 468dea0 commit 035cb16

File tree

68 files changed

+286
-185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+286
-185
lines changed

src/server/routes/admin/nonces.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ import {
1616
import { getChain } from "../../../utils/chain";
1717
import { redis } from "../../../utils/redis/redis";
1818
import { thirdwebClient } from "../../../utils/sdk";
19+
import { AddressSchema } from "../../schemas/address";
1920
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
2021
import { walletWithAddressParamSchema } from "../../schemas/wallet";
2122

2223
export const responseBodySchema = Type.Object({
2324
result: Type.Array(
2425
Type.Object({
25-
walletAddress: Type.String({
26-
description: "Backend Wallet Address",
27-
examples: ["0xcedf3b4d8f7f1f7e0f7f0f7f0f7f0f7f0f7f0f7f"],
28-
}),
26+
walletAddress: {
27+
...AddressSchema,
28+
description: "Backend wallet address",
29+
},
2930
chainId: Type.Number({
3031
description: "Chain ID",
3132
examples: [80002],

src/server/routes/auth/access-tokens/getAll.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { getAccessTokens } from "../../../../db/tokens/getAccessTokens";
5+
import { AddressSchema } from "../../../schemas/address";
56
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";
67

78
export const AccessTokenSchema = Type.Object({
89
id: Type.String(),
910
tokenMask: Type.String(),
10-
walletAddress: Type.String(),
11+
walletAddress: AddressSchema,
1112
createdAt: Type.String(),
1213
expiresAt: Type.String(),
1314
label: Type.Union([Type.String(), Type.Null()]),

src/server/routes/auth/permissions/getAll.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { prisma } from "../../../../db/client";
5+
import { AddressSchema } from "../../../schemas/address";
56
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";
67

78
const responseBodySchema = Type.Object({
89
result: Type.Array(
910
Type.Object({
10-
walletAddress: Type.String(),
11+
walletAddress: AddressSchema,
1112
permissions: Type.String(),
1213
label: Type.Union([Type.String(), Type.Null()]),
1314
}),

src/server/routes/auth/permissions/grant.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { updatePermissions } from "../../../../db/permissions/updatePermissions";
5+
import { AddressSchema } from "../../../schemas/address";
56
import { permissionsSchema } from "../../../schemas/auth";
67
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";
78

89
const requestBodySchema = Type.Object({
9-
walletAddress: Type.String(),
10+
walletAddress: AddressSchema,
1011
permissions: permissionsSchema,
1112
label: Type.Optional(Type.String()),
1213
});

src/server/routes/auth/permissions/revoke.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { deletePermissions } from "../../../../db/permissions/deletePermissions";
5+
import { AddressSchema } from "../../../schemas/address";
56
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";
67

78
const requestBodySchema = Type.Object({
8-
walletAddress: Type.String(),
9+
walletAddress: AddressSchema,
910
});
1011

1112
const responseBodySchema = Type.Object({

src/server/routes/backend-wallet/create.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { WalletType } from "../../../schema/wallet";
55
import { getConfig } from "../../../utils/cache/getConfig";
6+
import { AddressSchema } from "../../schemas/address";
67
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
78
import { createAwsKmsWallet } from "../../utils/wallets/createAwsKmsWallet";
89
import { createGcpKmsWallet } from "../../utils/wallets/createGcpKmsWallet";
@@ -14,7 +15,7 @@ const requestBodySchema = Type.Object({
1415

1516
const responseSchema = Type.Object({
1617
result: Type.Object({
17-
walletAddress: Type.String(),
18+
walletAddress: AddressSchema,
1819
status: Type.String(),
1920
}),
2021
});

src/server/routes/backend-wallet/getBalance.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { getSdk } from "../../../utils/cache/getSdk";
5+
import { AddressSchema } from "../../schemas/address";
56
import {
67
currencyValueSchema,
78
standardResponseSchema,
@@ -11,7 +12,7 @@ import { getChainIdFromChain } from "../../utils/chain";
1112

1213
const responseSchema = Type.Object({
1314
result: Type.Object({
14-
walletAddress: Type.String(),
15+
walletAddress: AddressSchema,
1516
...currencyValueSchema.properties,
1617
}),
1718
});

src/server/routes/backend-wallet/import.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { StatusCodes } from "http-status-codes";
44
import { WalletType } from "../../../schema/wallet";
55
import { getConfig } from "../../../utils/cache/getConfig";
66
import { createCustomError } from "../../middleware/error";
7+
import { AddressSchema } from "../../schemas/address";
78
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
89
import { importAwsKmsWallet } from "../../utils/wallets/importAwsKmsWallet";
910
import { importGcpKmsWallet } from "../../utils/wallets/importGcpKmsWallet";
@@ -80,7 +81,7 @@ RequestBodySchema.examples = [
8081

8182
const ResponseSchema = Type.Object({
8283
result: Type.Object({
83-
walletAddress: Type.String(),
84+
walletAddress: AddressSchema,
8485
status: Type.String(),
8586
}),
8687
});

src/server/routes/backend-wallet/remove.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { Address } from "thirdweb";
55
import { deleteWalletDetails } from "../../../db/wallets/deleteWalletDetails";
6+
import { AddressSchema } from "../../schemas/address";
67
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
78

89
const requestParamSchema = Type.Object({
9-
walletAddress: Type.String(),
10+
walletAddress: AddressSchema,
1011
});
1112

1213
const responseSchema = Type.Object({

src/server/routes/backend-wallet/sendTransaction.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { StatusCodes } from "http-status-codes";
44
import { Address, Hex } from "thirdweb";
55
import { maybeBigInt } from "../../../utils/primitiveTypes";
66
import { insertTransaction } from "../../../utils/transaction/insertTransaction";
7+
import { AddressSchema } from "../../schemas/address";
78
import {
89
requestQuerystringSchema,
910
standardResponseSchema,
@@ -18,11 +19,7 @@ import {
1819
import { getChainIdFromChain } from "../../utils/chain";
1920

2021
const requestBodySchema = Type.Object({
21-
toAddress: Type.Optional(
22-
Type.String({
23-
examples: ["0x..."],
24-
}),
25-
),
22+
toAddress: Type.Optional(AddressSchema),
2623
data: Type.String({
2724
examples: ["0x..."],
2825
}),

src/server/routes/backend-wallet/sendTransactionBatch.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { StatusCodes } from "http-status-codes";
44
import { Address, Hex } from "thirdweb";
55
import { maybeBigInt } from "../../../utils/primitiveTypes";
66
import { insertTransaction } from "../../../utils/transaction/insertTransaction";
7+
import { AddressSchema } from "../../schemas/address";
78
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
89
import { txOverridesWithValueSchema } from "../../schemas/txOverrides";
910
import {
@@ -14,11 +15,7 @@ import { getChainIdFromChain } from "../../utils/chain";
1415

1516
const requestBodySchema = Type.Array(
1617
Type.Object({
17-
toAddress: Type.Optional(
18-
Type.String({
19-
examples: ["0x..."],
20-
}),
21-
),
18+
toAddress: Type.Optional(AddressSchema),
2219
data: Type.String({
2320
examples: ["0x..."],
2421
}),

src/server/routes/backend-wallet/update.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { updateWalletDetails } from "../../../db/wallets/updateWalletDetails";
5+
import { AddressSchema } from "../../schemas/address";
56
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
67

78
const requestBodySchema = Type.Object({
8-
walletAddress: Type.String(),
9+
walletAddress: AddressSchema,
910
label: Type.Optional(Type.String()),
1011
});
1112

1213
const responseSchema = Type.Object({
1314
result: Type.Object({
14-
walletAddress: Type.String(),
15+
walletAddress: AddressSchema,
1516
status: Type.String(),
1617
}),
1718
});

src/server/routes/backend-wallet/withdraw.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { getWalletBalance } from "thirdweb/wallets";
1111
import { getAccount } from "../../../utils/account";
1212
import { getChain } from "../../../utils/chain";
1313
import { thirdwebClient } from "../../../utils/sdk";
14+
import { AddressSchema } from "../../schemas/address";
1415
import {
1516
requestQuerystringSchema,
1617
standardResponseSchema,
@@ -24,9 +25,10 @@ import { getChainIdFromChain } from "../../utils/chain";
2425
const ParamsSchema = Type.Omit(walletWithAddressParamSchema, ["walletAddress"]);
2526

2627
const requestBodySchema = Type.Object({
27-
toAddress: Type.String({
28+
toAddress: {
29+
...AddressSchema,
2830
description: "Address to withdraw all funds to",
29-
}),
31+
},
3032
});
3133

3234
const responseBodySchema = Type.Object({

src/server/routes/contract/events/getContractEventLogs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { StatusCodes } from "http-status-codes";
44
import { getContractEventLogsByBlockAndTopics } from "../../../../db/contractEventLogs/getContractEventLogs";
55
import { isContractSubscribed } from "../../../../db/contractSubscriptions/getContractSubscriptions";
66
import { createCustomError } from "../../../middleware/error";
7+
import { AddressSchema } from "../../../schemas/address";
78
import {
89
contractParamSchema,
910
standardResponseSchema,
@@ -21,7 +22,7 @@ const responseSchema = Type.Object({
2122
logs: Type.Array(
2223
Type.Object({
2324
chainId: Type.Number(),
24-
contractAddress: Type.String(),
25+
contractAddress: AddressSchema,
2526
blockNumber: Type.Number(),
2627
transactionHash: Type.String(),
2728
topics: Type.Array(Type.String()),

src/server/routes/contract/events/getEventLogsByTimestamp.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { Static, Type } from "@sinclair/typebox";
2-
import { FastifyInstance } from "fastify";
1+
import { Type, type Static } from "@sinclair/typebox";
2+
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { getEventLogsByBlockTimestamp } from "../../../../db/contractEventLogs/getContractEventLogs";
5+
import { AddressSchema } from "../../../schemas/address";
56
import { eventLogSchema } from "../../../schemas/eventLog";
67
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";
78

89
const requestQuerySchema = Type.Object({
9-
contractAddresses: Type.Optional(Type.Array(Type.String())),
10+
contractAddresses: Type.Optional(Type.Array(AddressSchema)),
1011
topics: Type.Optional(Type.Array(Type.String())),
1112
fromBlockTimestamp: Type.Number(),
1213
toBlockTimestamp: Type.Optional(Type.Number()),

src/server/routes/contract/events/paginateEventLogs.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import { Static, Type } from "@sinclair/typebox";
2-
import { FastifyInstance } from "fastify";
1+
import { Type, type Static } from "@sinclair/typebox";
2+
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { getConfiguration } from "../../../../db/configuration/getConfiguration";
55
import { getEventLogsByCursor } from "../../../../db/contractEventLogs/getContractEventLogs";
6+
import { AddressSchema } from "../../../schemas/address";
67
import { eventLogSchema, toEventLogSchema } from "../../../schemas/eventLog";
78
import { standardResponseSchema } from "../../../schemas/sharedApiSchemas";
89

910
const requestQuerySchema = Type.Object({
1011
cursor: Type.Optional(Type.String()),
1112
pageSize: Type.Optional(Type.Number()),
1213
topics: Type.Optional(Type.Array(Type.String())),
13-
contractAddresses: Type.Optional(Type.Array(Type.String())),
14+
contractAddresses: Type.Optional(Type.Array(AddressSchema)),
1415
});
1516

1617
const responseSchema = Type.Object({

src/server/routes/contract/extensions/account/write/grantAdmin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { queueTx } from "../../../../../../db/transactions/queueTx";
55
import { getContract } from "../../../../../../utils/cache/getContract";
6+
import { AddressSchema } from "../../../../../schemas/address";
67
import {
78
contractParamSchema,
89
requestQuerystringSchema,
@@ -14,9 +15,10 @@ import { walletWithAAHeaderSchema } from "../../../../../schemas/wallet";
1415
import { getChainIdFromChain } from "../../../../../utils/chain";
1516

1617
const requestBodySchema = Type.Object({
17-
signerAddress: Type.String({
18+
signerAddress: {
19+
...AddressSchema,
1820
description: "Address to grant admin permissions to",
19-
}),
21+
},
2022
...txOverridesWithValueSchema.properties,
2123
});
2224

src/server/routes/contract/extensions/account/write/revokeAdmin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { queueTx } from "../../../../../../db/transactions/queueTx";
55
import { getContract } from "../../../../../../utils/cache/getContract";
6+
import { AddressSchema } from "../../../../../schemas/address";
67
import {
78
contractParamSchema,
89
requestQuerystringSchema,
@@ -14,9 +15,10 @@ import { walletWithAAHeaderSchema } from "../../../../../schemas/wallet";
1415
import { getChainIdFromChain } from "../../../../../utils/chain";
1516

1617
const requestBodySchema = Type.Object({
17-
walletAddress: Type.String({
18+
walletAddress: {
19+
...AddressSchema,
1820
description: "Address to revoke admin permissions from",
19-
}),
21+
},
2022
...txOverridesWithValueSchema.properties,
2123
});
2224

src/server/routes/contract/extensions/account/write/revokeSession.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { queueTx } from "../../../../../../db/transactions/queueTx";
55
import { getContract } from "../../../../../../utils/cache/getContract";
6+
import { AddressSchema } from "../../../../../schemas/address";
67
import {
78
contractParamSchema,
89
requestQuerystringSchema,
@@ -14,9 +15,10 @@ import { walletWithAAHeaderSchema } from "../../../../../schemas/wallet";
1415
import { getChainIdFromChain } from "../../../../../utils/chain";
1516

1617
const requestBodySchema = Type.Object({
17-
walletAddress: Type.String({
18+
walletAddress: {
19+
...AddressSchema,
1820
description: "Address to revoke session from",
19-
}),
21+
},
2022
...txOverridesWithValueSchema.properties,
2123
});
2224

src/server/routes/contract/extensions/account/write/updateSession.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { queueTx } from "../../../../../../db/transactions/queueTx";
55
import { getContract } from "../../../../../../utils/cache/getContract";
6+
import { AddressSchema } from "../../../../../schemas/address";
67
import {
78
contractParamSchema,
89
requestQuerystringSchema,
@@ -14,8 +15,8 @@ import { walletWithAAHeaderSchema } from "../../../../../schemas/wallet";
1415
import { getChainIdFromChain } from "../../../../../utils/chain";
1516

1617
const requestBodySchema = Type.Object({
17-
signerAddress: Type.String(),
18-
approvedCallTargets: Type.Array(Type.String()),
18+
signerAddress: AddressSchema,
19+
approvedCallTargets: Type.Array(AddressSchema),
1920
startDate: Type.Optional(Type.String()),
2021
expirationDate: Type.Optional(Type.String()),
2122
nativeTokenLimitPerTransaction: Type.Optional(Type.String()),

src/server/routes/contract/extensions/accountFactory/read/getAssociatedAccounts.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { getContract } from "../../../../../../utils/cache/getContract";
5+
import { AddressSchema } from "../../../../../schemas/address";
56
import {
67
contractParamSchema,
78
standardResponseSchema,
@@ -16,9 +17,10 @@ const responseBodySchema = Type.Object({
1617
});
1718

1819
const QuerySchema = Type.Object({
19-
signerAddress: Type.String({
20+
signerAddress: {
21+
...AddressSchema,
2022
description: "The address of the signer to get associated accounts from",
21-
}),
23+
},
2224
});
2325

2426
export const getAssociatedAccounts = async (fastify: FastifyInstance) => {

0 commit comments

Comments
 (0)