Skip to content

Commit f89c8f7

Browse files
committed
setup foundations
1 parent ba59e74 commit f89c8f7

File tree

4 files changed

+85
-29
lines changed

4 files changed

+85
-29
lines changed

src/db/configuration/getConfiguration.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Static } from "@sinclair/typebox";
33
import { LocalWallet } from "@thirdweb-dev/wallets";
44
import { ethers } from "ethers";
55
import type { Chain } from "thirdweb";
6+
import { z } from "zod";
67
import type {
78
AwsWalletConfiguration,
89
GcpWalletConfiguration,
@@ -17,6 +18,17 @@ import { logger } from "../../utils/logger";
1718
import { prisma } from "../client";
1819
import { updateConfiguration } from "./updateConfiguration";
1920

21+
const circleCredentialSchema = z.object({
22+
apiKey: z.string(),
23+
entitySecret: z.string(),
24+
});
25+
26+
export type CircleCredential = z.infer<typeof circleCredentialSchema>;
27+
28+
export const walletProviderCredentialsSchema = z.object({
29+
cirlce: circleCredentialSchema.optional(),
30+
});
31+
2032
const toParsedConfig = async (config: Configuration): Promise<ParsedConfig> => {
2133
// We destructure the config to omit wallet related fields to prevent direct access
2234
const {
@@ -29,6 +41,7 @@ const toParsedConfig = async (config: Configuration): Promise<ParsedConfig> => {
2941
gcpApplicationCredentialEmail,
3042
gcpApplicationCredentialPrivateKey,
3143
contractSubscriptionsRetryDelaySeconds,
44+
walletProviderCredentials,
3245
...restConfig
3346
} = config;
3447

@@ -162,6 +175,22 @@ const toParsedConfig = async (config: Configuration): Promise<ParsedConfig> => {
162175
legacyWalletType_removeInNextBreakingChange = WalletType.gcpKms;
163176
}
164177

178+
const otherCredentials = walletProviderCredentialsSchema.parse(
179+
walletProviderCredentials,
180+
);
181+
182+
let circleCredentials: CircleCredential | null = null;
183+
184+
if (otherCredentials.cirlce) {
185+
circleCredentials = {
186+
apiKey: otherCredentials.cirlce.apiKey,
187+
entitySecret: decrypt(
188+
otherCredentials.cirlce.entitySecret,
189+
env.ENCRYPTION_PASSWORD,
190+
),
191+
};
192+
}
193+
165194
return {
166195
...restConfig,
167196
contractSubscriptionsRequeryDelaySeconds:
@@ -170,6 +199,7 @@ const toParsedConfig = async (config: Configuration): Promise<ParsedConfig> => {
170199
walletConfiguration: {
171200
aws: awsWalletConfiguration,
172201
gcp: gcpWalletConfiguration,
202+
circle: circleCredentials,
173203
legacyWalletType_removeInNextBreakingChange,
174204
},
175205
};
Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11
import type { Prisma } from "@prisma/client";
22
import { encrypt } from "../../utils/crypto";
33
import { prisma } from "../client";
4+
import { walletProviderCredentialsSchema } from "./getConfiguration";
45

56
export const updateConfiguration = async (
67
data: Prisma.ConfigurationUpdateArgs["data"],
78
) => {
9+
// ecnrypt AWS credential data
10+
if (typeof data.awsSecretAccessKey === "string") {
11+
data.awsSecretAccessKey = encrypt(data.awsSecretAccessKey);
12+
}
13+
14+
// ecnrypt GCP credential data
15+
if (typeof data.gcpApplicationCredentialPrivateKey === "string") {
16+
data.gcpApplicationCredentialPrivateKey = encrypt(
17+
data.gcpApplicationCredentialPrivateKey,
18+
);
19+
}
20+
21+
const walletProviderCredentials = walletProviderCredentialsSchema.parse(
22+
data.walletProviderCredentials,
23+
);
24+
25+
// Encrypt Circle credential data
26+
if (walletProviderCredentials.cirlce) {
27+
walletProviderCredentials.cirlce.entitySecret = encrypt(
28+
walletProviderCredentials.cirlce.entitySecret,
29+
);
30+
}
31+
832
return prisma.configuration.update({
933
where: {
1034
id: "default",
1135
},
1236
data: {
1337
...data,
14-
...(typeof data.awsSecretAccessKey === "string"
15-
? { awsSecretAccessKey: encrypt(data.awsSecretAccessKey) }
16-
: {}),
17-
...(typeof data.gcpApplicationCredentialPrivateKey === "string"
18-
? {
19-
gcpApplicationCredentialPrivateKey: encrypt(
20-
data.gcpApplicationCredentialPrivateKey,
21-
),
22-
}
23-
: {}),
38+
walletProviderCredentials,
2439
},
2540
});
2641
};

src/prisma/schema.prisma

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,26 +30,30 @@ model Configuration {
3030
contractSubscriptionsRetryDelaySeconds String @default("10") @map("contractSubscriptionsRetryDelaySeconds")
3131
3232
// AWS
33-
awsAccessKeyId String? @map("awsAccessKeyId") /// global config, precedence goes to WalletDetails
34-
awsSecretAccessKey String? @map("awsSecretAccessKey") /// global config, precedence goes to WalletDetails
35-
awsRegion String? @map("awsRegion") /// global config, treat as "default", store in WalletDetails.awsKmsArn
33+
awsAccessKeyId String? @map("awsAccessKeyId") /// global config, precedence goes to WalletDetails
34+
awsSecretAccessKey String? @map("awsSecretAccessKey") /// global config, precedence goes to WalletDetails
35+
awsRegion String? @map("awsRegion") /// global config, treat as "default", store in WalletDetails.awsKmsArn
3636
// GCP
37-
gcpApplicationProjectId String? @map("gcpApplicationProjectId") /// global config, treat as "default", store in WalletDetails.gcpKmsResourcePath
38-
gcpKmsLocationId String? @map("gcpKmsLocationId") /// global config, treat as "default", store in WalletDetails.gcpKmsResourcePath
39-
gcpKmsKeyRingId String? @map("gcpKmsKeyRingId") /// global config, treat as "default", store in WalletDetails.gcpKmsResourcePath
40-
gcpApplicationCredentialEmail String? @map("gcpApplicationCredentialEmail") /// global config, precedence goes to WalletDetails
41-
gcpApplicationCredentialPrivateKey String? @map("gcpApplicationCredentialPrivateKey") /// global config, precedence goes to WalletDetails
37+
gcpApplicationProjectId String? @map("gcpApplicationProjectId") /// global config, treat as "default", store in WalletDetails.gcpKmsResourcePath
38+
gcpKmsLocationId String? @map("gcpKmsLocationId") /// global config, treat as "default", store in WalletDetails.gcpKmsResourcePath
39+
gcpKmsKeyRingId String? @map("gcpKmsKeyRingId") /// global config, treat as "default", store in WalletDetails.gcpKmsResourcePath
40+
gcpApplicationCredentialEmail String? @map("gcpApplicationCredentialEmail") /// global config, precedence goes to WalletDetails
41+
gcpApplicationCredentialPrivateKey String? @map("gcpApplicationCredentialPrivateKey") /// global config, precedence goes to WalletDetails
42+
43+
// other wallet provider credentials
44+
walletProviderCredentials Json @default("{}") @map("walletProviderCredentials") /// GCP and AWS credentials are stored as rows in WalletDetails, but other providers are stored here
45+
4246
// Auth
43-
authDomain String @default("") @map("authDomain") // TODO: Remove defaults on major
44-
authWalletEncryptedJson String @default("") @map("authWalletEncryptedJson") // TODO: Remove defaults on major
47+
authDomain String @default("") @map("authDomain") // TODO: Remove defaults on major
48+
authWalletEncryptedJson String @default("") @map("authWalletEncryptedJson") // TODO: Remove defaults on major
4549
// Webhook
46-
webhookUrl String? @map("webhookUrl")
47-
webhookAuthBearerToken String? @map("webhookAuthBearerToken")
50+
webhookUrl String? @map("webhookUrl")
51+
webhookAuthBearerToken String? @map("webhookAuthBearerToken")
4852
// Wallet balance
49-
minWalletBalance String @default("20000000000000000") @map("minWalletBalance")
50-
accessControlAllowOrigin String @default("https://thirdweb.com,https://embed.ipfscdn.io") @map("accessControlAllowOrigin")
51-
ipAllowlist String[] @default([]) @map("ipAllowlist")
52-
clearCacheCronSchedule String @default("*/30 * * * * *") @map("clearCacheCronSchedule")
53+
minWalletBalance String @default("20000000000000000") @map("minWalletBalance")
54+
accessControlAllowOrigin String @default("https://thirdweb.com,https://embed.ipfscdn.io") @map("accessControlAllowOrigin")
55+
ipAllowlist String[] @default([]) @map("ipAllowlist")
56+
clearCacheCronSchedule String @default("*/30 * * * * *") @map("clearCacheCronSchedule")
5357
5458
@@map("configuration")
5559
}
@@ -94,10 +98,14 @@ model WalletDetails {
9498
gcpKmsResourcePath String? @map("gcpKmsResourcePath") @db.Text
9599
gcpApplicationCredentialEmail String? @map("gcpApplicationCredentialEmail") /// if not available, default to: Configuration.gcpApplicationCredentialEmail
96100
gcpApplicationCredentialPrivateKey String? @map("gcpApplicationCredentialPrivateKey") /// if not available, default to: Configuration.gcpApplicationCredentialPrivateKey
101+
102+
// other types of credentials
103+
credentials Json? @map("credentials")
104+
97105
// Smart Backend Wallet
98-
accountSignerAddress String? @map("accountSignerAddress") /// this, and either local, aws or gcp encryptedJson, are required for smart wallet
99-
accountFactoryAddress String? @map("accountFactoryAddress") /// optional even for smart wallet, if not available default factory will be used
100-
entrypointAddress String? @map("entrypointAddress") /// optional even for smart wallet, if not available SDK will use default entrypoint
106+
accountSignerAddress String? @map("accountSignerAddress") /// this, and either local, aws or gcp encryptedJson, are required for smart wallet
107+
accountFactoryAddress String? @map("accountFactoryAddress") /// optional even for smart wallet, if not available default factory will be used
108+
entrypointAddress String? @map("entrypointAddress") /// optional even for smart wallet, if not available SDK will use default entrypoint
101109
102110
@@map("wallet_details")
103111
}

src/schema/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Configuration } from "@prisma/client";
22
import type { Chain } from "thirdweb";
3+
import type { CircleCredential } from "../db/configuration/getConfiguration";
34
import type { WalletType } from "./wallet";
45

56
export type AwsWalletConfiguration = {
@@ -32,11 +33,13 @@ export interface ParsedConfig
3233
| "gcpKmsKeyRingId"
3334
| "gcpApplicationCredentialEmail"
3435
| "gcpApplicationCredentialPrivateKey"
36+
| "walletProviderCredentials"
3537
| "contractSubscriptionsRetryDelaySeconds"
3638
> {
3739
walletConfiguration: {
3840
aws: AwsWalletConfiguration | null;
3941
gcp: GcpWalletConfiguration | null;
42+
circle: CircleCredential | null;
4043
legacyWalletType_removeInNextBreakingChange: WalletType;
4144
};
4245
contractSubscriptionsRequeryDelaySeconds: string;

0 commit comments

Comments
 (0)