1
- import { Configuration } from "@prisma/client" ;
2
- import { Static } from "@sinclair/typebox" ;
1
+ import type { Configuration } from "@prisma/client" ;
2
+ import type { Static } from "@sinclair/typebox" ;
3
3
import { LocalWallet } from "@thirdweb-dev/wallets" ;
4
4
import { ethers } from "ethers" ;
5
- import { Chain } from "thirdweb" ;
6
- import { ParsedConfig } from "../../schema/config" ;
5
+ import type { Chain } from "thirdweb" ;
6
+ import type {
7
+ AwsWalletConfiguration ,
8
+ GcpWalletConfiguration ,
9
+ ParsedConfig ,
10
+ } from "../../schema/config" ;
7
11
import { WalletType } from "../../schema/wallet" ;
8
12
import { mandatoryAllowedCorsUrls } from "../../server/utils/cors-urls" ;
9
- import { networkResponseSchema } from "../../utils/cache/getSdk" ;
13
+ import type { networkResponseSchema } from "../../utils/cache/getSdk" ;
10
14
import { decrypt } from "../../utils/crypto" ;
11
15
import { env } from "../../utils/env" ;
12
16
import { logger } from "../../utils/logger" ;
@@ -53,6 +57,18 @@ const toParsedConfig = async (config: Configuration): Promise<ParsedConfig> => {
53
57
}
54
58
}
55
59
60
+ // LEGACY COMPATIBILITY
61
+ // legacy behaviour was to check for these in order:
62
+ // 1. AWS KMS Configuration - if found, wallet type is AWS KMS
63
+ // 2. GCP KMS Configuration - if found, wallet type is GCP KMS
64
+ // 3. If neither are found, wallet type is Local
65
+ // to maintain compatibility where users expect to call create new backend wallet endpoint without an explicit wallet type
66
+ // we need to preserve the wallet type in the configuration but only as the "default" wallet type
67
+ let legacyWalletType_removeInNextBreakingChange : WalletType =
68
+ WalletType . local ;
69
+
70
+ let awsWalletConfiguration : AwsWalletConfiguration | null = null ;
71
+
56
72
// TODO: Remove backwards compatibility with next breaking change
57
73
if ( awsAccessKeyId && awsSecretAccessKey && awsRegion ) {
58
74
// First try to load the aws secret using the encryption password
@@ -73,7 +89,8 @@ const toParsedConfig = async (config: Configuration): Promise<ParsedConfig> => {
73
89
logger ( {
74
90
service : "worker" ,
75
91
level : "info" ,
76
- message : `[Encryption] Updating awsSecretAccessKey to use ENCRYPTION_PASSWORD` ,
92
+ message :
93
+ "[Encryption] Updating awsSecretAccessKey to use ENCRYPTION_PASSWORD" ,
77
94
} ) ;
78
95
79
96
await updateConfiguration ( {
@@ -85,28 +102,18 @@ const toParsedConfig = async (config: Configuration): Promise<ParsedConfig> => {
85
102
// Renaming contractSubscriptionsRetryDelaySeconds
86
103
// to contractSubscriptionsRequeryDelaySeconds to reflect its purpose
87
104
// as we are requerying (& not retrying) with different delays
88
- return {
89
- ...restConfig ,
90
- contractSubscriptionsRequeryDelaySeconds :
91
- contractSubscriptionsRetryDelaySeconds ,
92
- chainOverridesParsed,
93
- walletConfiguration : {
94
- type : WalletType . awsKms ,
95
- awsRegion,
96
- awsAccessKeyId,
97
- awsSecretAccessKey : decryptedSecretAccessKey ,
98
- } ,
105
+ awsWalletConfiguration = {
106
+ awsAccessKeyId,
107
+ awsSecretAccessKey : decryptedSecretAccessKey ,
108
+ defaultAwsRegion : awsRegion ,
99
109
} ;
110
+
111
+ legacyWalletType_removeInNextBreakingChange = WalletType . awsKms ;
100
112
}
101
113
114
+ let gcpWalletConfiguration : GcpWalletConfiguration | null = null ;
102
115
// TODO: Remove backwards compatibility with next breaking change
103
- if (
104
- gcpApplicationProjectId &&
105
- gcpKmsLocationId &&
106
- gcpKmsKeyRingId &&
107
- gcpApplicationCredentialEmail &&
108
- gcpApplicationCredentialPrivateKey
109
- ) {
116
+ if ( gcpApplicationCredentialEmail && gcpApplicationCredentialPrivateKey ) {
110
117
// First try to load the gcp secret using the encryption password
111
118
let decryptedGcpKey = decrypt (
112
119
gcpApplicationCredentialPrivateKey ,
@@ -125,7 +132,8 @@ const toParsedConfig = async (config: Configuration): Promise<ParsedConfig> => {
125
132
logger ( {
126
133
service : "worker" ,
127
134
level : "info" ,
128
- message : `[Encryption] Updating gcpApplicationCredentialPrivateKey to use ENCRYPTION_PASSWORD` ,
135
+ message :
136
+ "[Encryption] Updating gcpApplicationCredentialPrivateKey to use ENCRYPTION_PASSWORD" ,
129
137
} ) ;
130
138
131
139
await updateConfiguration ( {
@@ -134,20 +142,24 @@ const toParsedConfig = async (config: Configuration): Promise<ParsedConfig> => {
134
142
}
135
143
}
136
144
137
- return {
138
- ...restConfig ,
139
- contractSubscriptionsRequeryDelaySeconds :
140
- contractSubscriptionsRetryDelaySeconds ,
141
- chainOverridesParsed,
142
- walletConfiguration : {
143
- type : WalletType . gcpKms ,
144
- gcpApplicationProjectId,
145
- gcpKmsLocationId,
146
- gcpKmsKeyRingId,
147
- gcpApplicationCredentialEmail,
148
- gcpApplicationCredentialPrivateKey : decryptedGcpKey ,
149
- } ,
145
+ if ( ! gcpKmsLocationId || ! gcpKmsKeyRingId || ! gcpApplicationProjectId ) {
146
+ throw new Error (
147
+ "GCP KMS location ID, project ID, and key ring ID are required configuration for this wallet type" ,
148
+ ) ;
149
+ }
150
+
151
+ gcpWalletConfiguration = {
152
+ gcpApplicationCredentialEmail,
153
+ gcpApplicationCredentialPrivateKey : decryptedGcpKey ,
154
+
155
+ // TODO: Remove these with the next breaking change
156
+ // These are used because import endpoint does not yet support GCP KMS resource path
157
+ defaultGcpKmsLocationId : gcpKmsLocationId ,
158
+ defaultGcpKmsKeyRingId : gcpKmsKeyRingId ,
159
+ defaultGcpApplicationProjectId : gcpApplicationProjectId ,
150
160
} ;
161
+
162
+ legacyWalletType_removeInNextBreakingChange = WalletType . gcpKms ;
151
163
}
152
164
153
165
return {
@@ -156,7 +168,9 @@ const toParsedConfig = async (config: Configuration): Promise<ParsedConfig> => {
156
168
contractSubscriptionsRetryDelaySeconds ,
157
169
chainOverridesParsed,
158
170
walletConfiguration : {
159
- type : WalletType . local ,
171
+ aws : awsWalletConfiguration ,
172
+ gcp : gcpWalletConfiguration ,
173
+ legacyWalletType_removeInNextBreakingChange,
160
174
} ,
161
175
} ;
162
176
} ;
0 commit comments