Skip to content

Commit

Permalink
fix(common): move kms account to its own export (#2731)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic authored Apr 25, 2024
1 parent 8493f88 commit 4b52372
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions .changeset/perfect-actors-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Added `createKmsAccount`, a [viem custom account](https://viem.sh/docs/accounts/
To use it, you must first install `@aws-sdk/[email protected]` and `[email protected]` dependencies into your project. Then create a KMS account with:

```ts
import { createKmsAccount } from "@latticexyz/common/kms";
const account = createKmsAccount({ keyId: ... });
```

Expand Down
6 changes: 5 additions & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"./errors": "./dist/errors.js",
"./foundry": "./dist/foundry.js",
"./type-utils": "./dist/type-utils.js",
"./utils": "./dist/utils.js"
"./utils": "./dist/utils.js",
"./kms": "./dist/kms.js"
},
"typesVersions": {
"*": {
Expand All @@ -44,6 +45,9 @@
],
"utils": [
"./src/utils/index.ts"
],
"kms": [
"./src/exports/kms.ts"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { KMSClient } from "@aws-sdk/client-kms";
import { LocalAccount, hashMessage, hashTypedData, keccak256, serializeTransaction } from "viem";
import { toAccount } from "viem/accounts";
import { signWithKms } from "./account/kms/signWithKms";
import { getAddressFromKMS } from "./account/kms/getAddressFromKms";
import { signWithKms } from "./signWithKms";
import { getAddressFromKms } from "./getAddressFromKms";

export type CreateKmsAccountOptions = {
keyId: string;
Expand All @@ -20,7 +20,7 @@ export async function createKmsAccount({
keyId,
client = new KMSClient(),
}: CreateKmsAccountOptions): Promise<KMSAccount> {
const address = await getAddressFromKMS({ keyId, client });
const address = await getAddressFromKms({ keyId, client });

const account = toAccount({
address,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/account/kms/getAddressFromKms.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Address, toHex } from "viem";
import { publicKeyToAddress } from "viem/utils";
import { KMSClient, SignCommandInput } from "@aws-sdk/client-kms";
import { getPublicKey } from "./commands/getPublicKey";
import { getPublicKey } from "./getPublicKey";
// @ts-expect-error Could not find a declaration file for module 'asn1.js'.
import asn1 from "asn1.js";

Expand All @@ -21,7 +21,7 @@ function publicKeyKmsToAddress(publicKey: Uint8Array): Address {
return address;
}

export async function getAddressFromKMS({
export async function getAddressFromKms({
keyId,
client,
}: {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/common/src/account/kms/signWithKms.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Hex, isAddressEqual, signatureToHex, toHex } from "viem";
import { recoverAddress } from "viem/utils";
import { KMSClient, SignCommandInput } from "@aws-sdk/client-kms";
import { sign } from "./commands/sign";
import { sign } from "./sign";
// @ts-expect-error Could not find a declaration file for module 'asn1.js'.
import asn1 from "asn1.js";

Expand Down
1 change: 1 addition & 0 deletions packages/common/src/exports/kms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { createKmsAccount, type CreateKmsAccountOptions, type KMSAccount } from "../account/kms/createKmsAccount";
1 change: 0 additions & 1 deletion packages/common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from "./common";
export * from "./createBenchmark";
export * from "./createBurnerAccount";
export * from "./createKmsAccount";
export * from "./createNonceManager";
export * from "./getContract";
export * from "./getBurnerPrivateKey";
Expand Down
1 change: 1 addition & 0 deletions packages/common/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default defineConfig({
foundry: "src/foundry/index.ts",
"type-utils": "src/type-utils/index.ts",
utils: "src/utils/index.ts",
kms: "src/exports/kms.ts",
},
target: "esnext",
format: ["esm"],
Expand Down

0 comments on commit 4b52372

Please sign in to comment.