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" ;
33import { LocalWallet } from "@thirdweb-dev/wallets" ;
44import { 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" ;
711import { WalletType } from "../../schema/wallet" ;
812import { mandatoryAllowedCorsUrls } from "../../server/utils/cors-urls" ;
9- import { networkResponseSchema } from "../../utils/cache/getSdk" ;
13+ import type { networkResponseSchema } from "../../utils/cache/getSdk" ;
1014import { decrypt } from "../../utils/crypto" ;
1115import { env } from "../../utils/env" ;
1216import { logger } from "../../utils/logger" ;
@@ -53,6 +57,18 @@ const toParsedConfig = async (config: Configuration): Promise<ParsedConfig> => {
5357 }
5458 }
5559
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+
5672 // TODO: Remove backwards compatibility with next breaking change
5773 if ( awsAccessKeyId && awsSecretAccessKey && awsRegion ) {
5874 // First try to load the aws secret using the encryption password
@@ -73,7 +89,8 @@ const toParsedConfig = async (config: Configuration): Promise<ParsedConfig> => {
7389 logger ( {
7490 service : "worker" ,
7591 level : "info" ,
76- message : `[Encryption] Updating awsSecretAccessKey to use ENCRYPTION_PASSWORD` ,
92+ message :
93+ "[Encryption] Updating awsSecretAccessKey to use ENCRYPTION_PASSWORD" ,
7794 } ) ;
7895
7996 await updateConfiguration ( {
@@ -85,28 +102,18 @@ const toParsedConfig = async (config: Configuration): Promise<ParsedConfig> => {
85102 // Renaming contractSubscriptionsRetryDelaySeconds
86103 // to contractSubscriptionsRequeryDelaySeconds to reflect its purpose
87104 // 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 ,
99109 } ;
110+
111+ legacyWalletType_removeInNextBreakingChange = WalletType . awsKms ;
100112 }
101113
114+ let gcpWalletConfiguration : GcpWalletConfiguration | null = null ;
102115 // 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 ) {
110117 // First try to load the gcp secret using the encryption password
111118 let decryptedGcpKey = decrypt (
112119 gcpApplicationCredentialPrivateKey ,
@@ -125,7 +132,8 @@ const toParsedConfig = async (config: Configuration): Promise<ParsedConfig> => {
125132 logger ( {
126133 service : "worker" ,
127134 level : "info" ,
128- message : `[Encryption] Updating gcpApplicationCredentialPrivateKey to use ENCRYPTION_PASSWORD` ,
135+ message :
136+ "[Encryption] Updating gcpApplicationCredentialPrivateKey to use ENCRYPTION_PASSWORD" ,
129137 } ) ;
130138
131139 await updateConfiguration ( {
@@ -134,20 +142,24 @@ const toParsedConfig = async (config: Configuration): Promise<ParsedConfig> => {
134142 }
135143 }
136144
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 ,
150160 } ;
161+
162+ legacyWalletType_removeInNextBreakingChange = WalletType . gcpKms ;
151163 }
152164
153165 return {
@@ -156,7 +168,9 @@ const toParsedConfig = async (config: Configuration): Promise<ParsedConfig> => {
156168 contractSubscriptionsRetryDelaySeconds ,
157169 chainOverridesParsed,
158170 walletConfiguration : {
159- type : WalletType . local ,
171+ aws : awsWalletConfiguration ,
172+ gcp : gcpWalletConfiguration ,
173+ legacyWalletType_removeInNextBreakingChange,
160174 } ,
161175 } ;
162176} ;
0 commit comments