Building kms-viem-account-mini: a minimal AWS KMS signer for viem
Hi, I’m asuma, and I’m building blockchain × AI products at DaikoAI
Building kms-viem-account-mini: a minimal AWS KMS signer for viem
Hi, I’m asuma, and I’m building blockchain × AI products at DaikoAI
As the title suggests, I recently built and released kms-viem-account-mini, a small library for signing with AWS KMS in viem with minimal dependencies.
Why I built it
When you search for viem + KMS related solutions, one of the first libraries you’ll find is cloud-cryptographic-wallet by odan. There is also a Zenn article explaining how to adapt it for viem:
That said, with the growing number of supply-chain attacks and dependency-related incidents, I wanted something more narrowly scoped: a lightweight, simple, and secure library dedicated specifically to viem + AWS KMS.
So I decided to build it myself.
Usage
The API is very straightforward. You create a KMS-backed viem-compatible Account with createKmsAccount(), then pass it into viem’s walletClient.
With only a few extra lines, you can turn an existing viem setup into a KMS-backed wallet client.
import { createKmsAccount } from "kms-viem-account-mini";
import { createWalletClient, http } from "viem";
import { sepolia } from "viem/chains";
const account = await createKmsAccount({
keyId: process.env.AWS_KMS_KEY_ID!,
region: "ap-northeast-1",
});
const walletClient = createWalletClient({
account,
chain: sepolia,
transport: http("https://ethereum-sepolia-rpc.publicnode.com"),
});
const message = "hello from AWS KMS";
const signature = await walletClient.signMessage({
account,
message,
});
console.log({
address: account.address,
message,
signature,
});
Implementation
This library is intentionally lightweight and depends on only two packages:
Compared to existing alternatives, its main characteristics are:
- focused only on AWS KMS + viem
- a minimal ASN.1 parser implemented directly in TypeScript for only the required cases
- compatible with both JSR and npm, with native Deno support
Focused only on AWS KMS + viem
Unlike more general-purpose libraries such as cloud-cryptographic-wallet, I intentionally dropped support for multiple cloud providers and other Ethereum client libraries like ethers.js or web3.js.
The goal was to optimize for a modern, specific use case and eliminate unnecessary dependencies wherever possible.
Implementing only the ASN.1 parsing we actually need
AWS KMS returns signatures as ASN.1 DER-encoded byte arrays.
Many existing libraries rely on packages such as asn1.js
to deserialize them. But in this case, the actual parsing requirements are very limited.
For the EVM signing flow with ECC_SECG_P256K1, the only DER structures we really need to handle are:
- the SubjectPublicKeyInfo DER returned by GetPublicKey
- the SEQUENCE(INTEGER r, INTEGER s) DER returned by Sign
In other words, the required flow is basically just:
- fetch the public key
- request a signature and parse the returned signature
That means a full ASN.1 implementation is unnecessary for this use case. So I implemented support only for these two specific cases:
- GetPublicKey → parse SubjectPublicKeyInfo
- Sign → parse SEQUENCE(INTEGER r, INTEGER s)
Relevant source files:
JSR / npm compatible, with native Deno support
I also implemented the library using Deno.
A small but important detail is that I use minimumDependencyAge and nodeModulesDir: “none” to reduce the risk of unexpected installs or silent dependency version drift.
At runtime, Deno also lets you constrain the execution scope explicitly with flags such as — allow-env, which makes it easier to run scripts in a more controlled and secure way.
Closing thoughts
If you have any questions, feedback, or suggestions about the library, feel free to reach out on Zenn or X. Issues and PRs are also very welcome.
[embed]JavaScript is not available. Edit descriptionx.com
References
메타데이터
- post_id
- 5f475c2691c6
- slug
- building-kms-viem-account-mini-a-minimal-aws-kms-signer-for-viem-5f475c2691c6
- url
- https://medium.com/@posaune0423/building-kms-viem-account-mini-a-minimal-aws-kms-signer-for-viem-5f475c2691c6
- canonical_url
- https://medium.com/@posaune0423/building-kms-viem-account-mini-a-minimal-aws-kms-signer-for-viem-5f475c2691c6
- author_url
- https://medium.com/@posaune0423
- status
- ok
- fetched_at
- 2026-06-15 20:49:13