Skip to content

Commit

Permalink
feat(cli): deploy with kms (#2704)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <[email protected]>
  • Loading branch information
yonadaaa and holic authored Apr 25, 2024
1 parent 1ccd627 commit c74a664
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-teachers-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/cli": patch
---

Added a `--awsKmsKeyId` flag to `mud deploy` that deploys the world using an AWS KMS key as a transaction signer.
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"test:ci": "pnpm run test"
},
"dependencies": {
"@aws-sdk/client-kms": "^3.556.0",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@improbable-eng/grpc-web": "^0.15.0",
Expand All @@ -45,6 +46,7 @@
"@latticexyz/utils": "workspace:*",
"@latticexyz/world": "workspace:*",
"@latticexyz/world-modules": "workspace:*",
"asn1.js": "^5.4.1",
"chalk": "^5.0.1",
"chokidar": "^3.5.3",
"debug": "^4.3.4",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/commands/dev-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const commandModule: CommandModule<typeof devOptions, InferredOptionTypes<typeof
worldAddress,
srcDir,
salt: "0x",
awsKmsKeyId: undefined,
});
worldAddress = deploy.address;
// if there were changes while we were deploying, trigger it again
Expand Down
10 changes: 9 additions & 1 deletion packages/cli/src/runDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getChainId } from "viem/actions";
import { postDeploy } from "./utils/postDeploy";
import { WorldDeploy } from "./deploy/common";
import { build } from "./build";
import { kmsKeyToAccount } from "@latticexyz/common/kms";

export const deployOptions = {
configPath: { type: "string", desc: "Path to the MUD config file" },
Expand Down Expand Up @@ -42,6 +43,10 @@ export const deployOptions = {
type: "string",
desc: "The deployment salt to use. Defaults to a random salt.",
},
awsKmsKeyId: {
type: "string",
desc: "Optional AWS KMS key ID. If set, the World is deployed using a KMS signer instead of local private key.",
},
} as const satisfies Record<string, Options>;

export type DeployOptions = InferredOptionTypes<typeof deployOptions>;
Expand Down Expand Up @@ -90,6 +95,9 @@ 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 client = createWalletClient({
transport: http(rpc, {
batch: opts.rpcBatch
Expand All @@ -99,7 +107,7 @@ in your contracts directory to use the default anvil private key.`,
}
: undefined,
}),
account: privateKeyToAccount(privateKey),
account,
});

console.log("Deploying from", client.account.address);
Expand Down
1 change: 0 additions & 1 deletion packages/common/src/account/kms/kmsKeyToAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export type KmsAccount = LocalAccount<"aws-kms"> & {
*
* @returns A Local Account.
*/

export async function kmsKeyToAccount({
keyId,
client = new KMSClient(),
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c74a664

Please sign in to comment.