Skip to content

Commit 806c37e

Browse files
authored
decrypt wallet credential before use (#725)
* decrypt wallet credential before use * decrypt GCP application credential private key
1 parent 42ee0b0 commit 806c37e

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/utils/cache/getWallet.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { splitAwsKmsArn } from "../../server/utils/wallets/awsKmsArn";
1010
import { splitGcpKmsResourcePath } from "../../server/utils/wallets/gcpKmsResourcePath";
1111
import { getLocalWallet } from "../../server/utils/wallets/getLocalWallet";
1212
import { getSmartWallet } from "../../server/utils/wallets/getSmartWallet";
13+
import { decrypt } from "../crypto";
14+
import { env } from "../env";
1315
import { getConfig } from "./getConfig";
1416

1517
export const walletsCache = new Map<string, EVMWallet>();
@@ -64,9 +66,9 @@ export const getWallet = async <TWallet extends EVMWallet>({
6466
walletDetails.awsKmsAccessKeyId ??
6567
config.walletConfiguration.aws?.awsAccessKeyId;
6668

67-
const secretAccessKey =
68-
walletDetails.awsKmsSecretAccessKey ??
69-
config.walletConfiguration.aws?.awsSecretAccessKey;
69+
const secretAccessKey = walletDetails.awsKmsSecretAccessKey
70+
? decrypt(walletDetails.awsKmsSecretAccessKey, env.ENCRYPTION_PASSWORD)
71+
: config.walletConfiguration.aws?.awsSecretAccessKey;
7072

7173
if (!(accessKeyId && secretAccessKey)) {
7274
throw new Error(
@@ -95,9 +97,12 @@ export const getWallet = async <TWallet extends EVMWallet>({
9597
const email =
9698
walletDetails.gcpApplicationCredentialEmail ??
9799
config.walletConfiguration.gcp?.gcpApplicationCredentialEmail;
98-
const privateKey =
99-
walletDetails.gcpApplicationCredentialPrivateKey ??
100-
config.walletConfiguration.gcp?.gcpApplicationCredentialPrivateKey;
100+
const privateKey = walletDetails.gcpApplicationCredentialPrivateKey
101+
? decrypt(
102+
walletDetails.gcpApplicationCredentialPrivateKey,
103+
env.ENCRYPTION_PASSWORD,
104+
)
105+
: config.walletConfiguration.gcp?.gcpApplicationCredentialPrivateKey;
101106

102107
if (!(email && privateKey)) {
103108
throw new Error(

0 commit comments

Comments
 (0)