Skip to content

Commit

Permalink
decrypt wallet credential before use (#725)
Browse files Browse the repository at this point in the history
* decrypt wallet credential before use

* decrypt GCP application credential private key
  • Loading branch information
d4mr authored Oct 11, 2024
1 parent 42ee0b0 commit 806c37e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/utils/cache/getWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { splitAwsKmsArn } from "../../server/utils/wallets/awsKmsArn";
import { splitGcpKmsResourcePath } from "../../server/utils/wallets/gcpKmsResourcePath";
import { getLocalWallet } from "../../server/utils/wallets/getLocalWallet";
import { getSmartWallet } from "../../server/utils/wallets/getSmartWallet";
import { decrypt } from "../crypto";
import { env } from "../env";
import { getConfig } from "./getConfig";

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

const secretAccessKey =
walletDetails.awsKmsSecretAccessKey ??
config.walletConfiguration.aws?.awsSecretAccessKey;
const secretAccessKey = walletDetails.awsKmsSecretAccessKey
? decrypt(walletDetails.awsKmsSecretAccessKey, env.ENCRYPTION_PASSWORD)
: config.walletConfiguration.aws?.awsSecretAccessKey;

if (!(accessKeyId && secretAccessKey)) {
throw new Error(
Expand Down Expand Up @@ -95,9 +97,12 @@ export const getWallet = async <TWallet extends EVMWallet>({
const email =
walletDetails.gcpApplicationCredentialEmail ??
config.walletConfiguration.gcp?.gcpApplicationCredentialEmail;
const privateKey =
walletDetails.gcpApplicationCredentialPrivateKey ??
config.walletConfiguration.gcp?.gcpApplicationCredentialPrivateKey;
const privateKey = walletDetails.gcpApplicationCredentialPrivateKey
? decrypt(
walletDetails.gcpApplicationCredentialPrivateKey,
env.ENCRYPTION_PASSWORD,
)
: config.walletConfiguration.gcp?.gcpApplicationCredentialPrivateKey;

if (!(email && privateKey)) {
throw new Error(
Expand Down

0 comments on commit 806c37e

Please sign in to comment.