Skip to content

Commit 068ae71

Browse files
committed
always store kms credentials in WalletDetails
1 parent aa90ec0 commit 068ae71

File tree

5 files changed

+7
-50
lines changed

5 files changed

+7
-50
lines changed

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,11 @@ export const importBackendWallet = async (fastify: FastifyInstance) => {
166166
);
167167
}
168168

169-
const shouldOverrideCredentials = !!(
170-
credentials?.awsAccessKeyId && credentials?.awsSecretAccessKey
171-
);
172-
173169
walletAddress = await importAwsKmsWallet({
174170
awsKmsArn,
175171
crendentials: {
176172
accessKeyId,
177173
secretAccessKey,
178-
shouldStore: shouldOverrideCredentials,
179174
},
180175
label,
181176
});
@@ -191,12 +186,6 @@ export const importBackendWallet = async (fastify: FastifyInstance) => {
191186
credentials?.privateKey ??
192187
config.walletConfiguration.gcp?.gcpApplicationCredentialPrivateKey;
193188

194-
// if email and privateKey are provided in the request, then they should be stored in walletDetails
195-
// they are considered to override the global configuration
196-
const shouldOverrideCredentials = !!(
197-
credentials?.email && credentials?.privateKey
198-
);
199-
200189
if (!(email && privateKey)) {
201190
throw createCustomError(
202191
`Please provide 'email' and 'privateKey' to import a wallet. Can be provided as configuration or as credential with the request.`,
@@ -236,7 +225,6 @@ export const importBackendWallet = async (fastify: FastifyInstance) => {
236225
credentials: {
237226
email,
238227
privateKey,
239-
shouldStore: shouldOverrideCredentials,
240228
},
241229
label,
242230
});

src/server/utils/wallets/createAwsKmsWallet.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,13 @@ export const createAwsKmsWallet = async ({
5353
throw new Error("Failed to create AWS KMS key");
5454
}
5555

56-
const wereCredentialsOverridden = !!(
57-
overrides.awsSecretAccessKey && overrides.awsAccessKeyId
58-
);
59-
6056
const awsKmsArn = res.KeyMetadata.Arn;
6157
return importAwsKmsWallet({
6258
awsKmsArn,
6359
label,
6460
crendentials: {
6561
accessKeyId: kmsWalletParams.awsAccessKeyId,
6662
secretAccessKey: kmsWalletParams.awsSecretAccessKey,
67-
shouldStore: wereCredentialsOverridden,
6863
},
6964
});
7065
};

src/server/utils/wallets/createGcpKmsWallet.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,15 @@ export const createGcpKmsWallet = async ({
9393

9494
const walletAddress = account.address;
9595

96-
// if email and privateKey are provided explicitly in the request, then they should be stored in walletDetails
97-
const areCredentialsOverridden = !!(
98-
overrides.gcpApplicationCredentialEmail &&
99-
overrides.gcpApplicationCredentialPrivateKey
100-
);
101-
10296
await createWalletDetails({
10397
type: WalletType.gcpKms,
10498
address: walletAddress,
10599
label,
106100
gcpKmsResourcePath: resourcePath,
107101

108-
...(areCredentialsOverridden
109-
? {
110-
gcpApplicationCredentialEmail: params.gcpApplicationCredentialEmail,
111-
gcpApplicationCredentialPrivateKey:
112-
params.gcpApplicationCredentialPrivateKey,
113-
}
114-
: {}),
102+
gcpApplicationCredentialEmail: params.gcpApplicationCredentialEmail,
103+
gcpApplicationCredentialPrivateKey:
104+
params.gcpApplicationCredentialPrivateKey,
115105
});
116106

117107
return walletAddress;

src/server/utils/wallets/importAwsKmsWallet.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,13 @@ interface ImportAwsKmsWalletParams {
99
crendentials: {
1010
accessKeyId: string;
1111
secretAccessKey: string;
12-
/**
13-
* If true, the AWS access key and secret access key will be stored
14-
* along with the wallet details, separately from the global configuration
15-
*/
16-
shouldStore?: boolean;
1712
};
1813
label?: string;
1914
}
2015

2116
/**
2217
* Import an AWS KMS wallet, and store it into the database
2318
*
24-
* If credentials.shouldStore is true, the AWS access key and secret access key will be stored
25-
* along with the wallet details, separately from the global configuration
2619
*/
2720
export const importAwsKmsWallet = async ({
2821
crendentials,
@@ -50,12 +43,8 @@ export const importAwsKmsWallet = async ({
5043
awsKmsArn,
5144
label,
5245

53-
...(crendentials.shouldStore
54-
? {
55-
awsAccessKeyId: crendentials.accessKeyId,
56-
awsSecretAccessKey: crendentials.secretAccessKey,
57-
}
58-
: {}),
46+
awsKmsAccessKeyId: crendentials.accessKeyId,
47+
awsKmsSecretAccessKey: crendentials.secretAccessKey,
5948
});
6049

6150
return walletAddress;

src/server/utils/wallets/importGcpKmsWallet.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ interface ImportGcpKmsWalletParams {
99
credentials: {
1010
email: string;
1111
privateKey: string;
12-
shouldStore?: boolean;
1312
};
1413
}
1514

@@ -43,12 +42,8 @@ export const importGcpKmsWallet = async ({
4342
label,
4443
gcpKmsResourcePath,
4544

46-
...(credentials.shouldStore
47-
? {
48-
gcpApplicationCredentialEmail: credentials.email,
49-
gcpApplicationCredentialPrivateKey: credentials.privateKey,
50-
}
51-
: {}),
45+
gcpApplicationCredentialEmail: credentials.email,
46+
gcpApplicationCredentialPrivateKey: credentials.privateKey,
5247
});
5348

5449
return walletAddress;

0 commit comments

Comments
 (0)