Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/server/utils/wallets/getGcpKmsAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,28 @@ export async function getGcpKmsAccount(
): Promise<GcpKmsAccount> {
const { name: unprocessedName, clientOptions, client } = options;

let rawPrivateKey: string | undefined;
if (clientOptions?.credentials) {
if ("private_key" in clientOptions.credentials) {
rawPrivateKey = clientOptions.credentials.private_key;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO a bit clearer to just "sanitize" the private key in clientOptions and continue passing the clientOptions below.

  if (clientOptions?.credentials) {
    if ("private_key" in clientOptions.credentials) {
      clientOptions.credentials.private_key =
        clientOptions.credentials.private_key?.split(String.raw`\n`).join("\n");
    }
  }


// we had a bug previously where we previously called it "cryptoKeyVersion" instead of "cryptoKeyVersions"
// if we detect that, we'll fix it here
// TODO: remove this as a breaking change
const name = unprocessedName.includes("cryptoKeyVersions")
? unprocessedName
: unprocessedName.replace("cryptoKeyVersion", "cryptoKeyVersions");

const signer = new CloudKmsSigner(name, clientOptions);
const signer = new CloudKmsSigner(name, {
...clientOptions,
credentials: {
...clientOptions?.credentials,
// https://stackoverflow.com/questions/74131595/error-error1e08010cdecoder-routinesunsupported-with-google-auth-library
private_key: rawPrivateKey?.split(String.raw`\n`).join("\n"),
},
});

// Populate address immediately
const publicKey = await signer.getPublicKey();
Expand Down
5 changes: 4 additions & 1 deletion src/utils/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ export const getAccount = async (args: {
clientOptions: {
credentials: {
client_email: gcpApplicationCredentialEmail,
private_key: gcpApplicationCredentialPrivateKey,
// https://stackoverflow.com/questions/74131595/error-error1e08010cdecoder-routinesunsupported-with-google-auth-library
private_key: gcpApplicationCredentialPrivateKey
.split(String.raw`\n`)
.join("\n"),
},
},
});
Expand Down
Loading