Skip to content

Commit

Permalink
fix(cli): do not require PRIVATE_KEY if using KMS (#2765)
Browse files Browse the repository at this point in the history
  • Loading branch information
yonadaaa authored Apr 29, 2024
1 parent 93690fd commit 3031868
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-starfishes-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/cli": patch
---

Fixed `mud deploy` to not require the `PRIVATE_KEY` environment variable when using a KMS signer.
28 changes: 17 additions & 11 deletions packages/cli/src/runDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,25 @@ export async function runDeploy(opts: DeployOptions): Promise<WorldDeploy> {
await build({ config: configV2, srcDir, foundryProfile: profile });
}

const privateKey = process.env.PRIVATE_KEY as Hex;
if (!privateKey) {
throw new MUDError(
`Missing PRIVATE_KEY environment variable.
Run 'echo "PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" > .env'
in your contracts directory to use the default anvil private key.`,
);
}

const resolvedConfig = resolveConfig({ config, forgeSourceDir: srcDir, forgeOutDir: outDir });

const keyId = opts.awsKmsKeyId ?? process.env.AWS_KMS_KEY_ID;
const account = keyId ? await kmsKeyToAccount({ keyId }) : privateKeyToAccount(privateKey);
const account = await (async () => {
if (opts.awsKmsKeyId) {
const keyId = opts.awsKmsKeyId ?? process.env.AWS_KMS_KEY_ID;
return await kmsKeyToAccount({ keyId });
} else {
const privateKey = process.env.PRIVATE_KEY;
if (!privateKey) {
throw new MUDError(
`Missing PRIVATE_KEY environment variable.
Run 'echo "PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" > .env'
in your contracts directory to use the default anvil private key.`,
);
}

return privateKeyToAccount(privateKey as Hex);
}
})();

const client = createWalletClient({
transport: http(rpc, {
Expand Down

0 comments on commit 3031868

Please sign in to comment.