Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: AWS KMS Signer #4289

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

feat: AWS KMS Signer #4289

wants to merge 5 commits into from

Conversation

d4mr
Copy link
Member

@d4mr d4mr commented Aug 27, 2024

PR-Codex overview

This PR adds AWS KMS integration for secure key management, including configuration setup, account creation, and signing operations.

Detailed summary

  • Added AWS KMS signer library for secure key management
  • Updated package dependencies for AWS SDK and vitest
  • Implemented AWS KMS configuration setup and account creation
  • Added tests for AWS KMS integration with sign, verify, and transaction functions

The following files were skipped due to too many changes: pnpm-lock.yaml

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

vercel bot commented Aug 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 28, 2024 6:12pm
thirdweb_playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 28, 2024 6:12pm
thirdweb-www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 28, 2024 6:12pm
wallet-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 28, 2024 6:12pm

Copy link

changeset-bot bot commented Aug 27, 2024

⚠️ No Changeset found

Latest commit: 6be76fb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

graphite-app bot commented Aug 27, 2024

Your org requires the Graphite merge queue for merging into main

Add the label “merge-queue” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

Copy link

socket-security bot commented Aug 27, 2024

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@aws-sdk/[email protected] Transitive: environment, filesystem, network, shell +73 5.78 MB aws-sdk-bot
npm/[email protected] Transitive: environment, filesystem +20 4.47 MB odanado

View full report↗︎

export async function getAwsKmsAccount(
options: AwsKmsAccountOptions,
): Promise<Account> {
if (typeof Buffer === "undefined") {
Copy link
Member Author

Choose a reason for hiding this comment

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

because we don't polyfill Buffer, and we don't expect folks to use AWS KMS on browsers, I have explicitly safeguarded against browser usage

Copy link
Contributor

github-actions bot commented Aug 27, 2024

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 43.25 KB (0%) 865 ms (0%) 3.3 s (+1.16% 🔺) 4.2 s
thirdweb (cjs) 92.43 KB (0%) 1.9 s (0%) 8.2 s (+10.72% 🔺) 10.1 s
thirdweb (minimal + tree-shaking) 4.81 KB (0%) 97 ms (0%) 381 ms (+15.39% 🔺) 477 ms
thirdweb/chains (tree-shaking) 492 B (0%) 10 ms (0%) 97 ms (+5.19% 🔺) 107 ms
thirdweb/react (minimal + tree-shaking) 16.06 KB (0%) 322 ms (0%) 724 ms (+97.16% 🔺) 1.1 s

packages/thirdweb/src/wallets/aws-kms.test.ts Outdated Show resolved Hide resolved
packages/thirdweb/src/wallets/aws-kms.test.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,129 @@
import type { KMSClientConfig } from "@aws-sdk/client-kms";
import { KmsSigner } from "aws-kms-signer";
import type {
Copy link
Member

Choose a reason for hiding this comment

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

Why viem?

Copy link
Member Author

Choose a reason for hiding this comment

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

just used private-key.ts as reference, is there a different import I should do?

packages/thirdweb/src/wallets/aws-kms.ts Outdated Show resolved Hide resolved
packages/thirdweb/src/wallets/aws-kms.ts Outdated Show resolved Hide resolved
packages/thirdweb/src/wallets/aws-kms.ts Outdated Show resolved Hide resolved
}): Promise<Hex> {
let messageHash: Hex;
if (typeof message === "string") {
const prefixedMessage = `\x19Ethereum Signed Message:\n${message.length}${message}`;
Copy link
Member

Choose a reason for hiding this comment

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

What's this prefix?

Copy link
Member Author

@d4mr d4mr Aug 28, 2024

Choose a reason for hiding this comment

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

This is the required prefix for eth_sign & personal_sign according to spec (EIP191): ethereum/go-ethereum#3731 (comment)
https://docs.walletconnect.com/advanced/multichain/rpc-reference/ethereum-rpc#personal_sign
(sorry for the poor sources, can't find good ones after eth migrated their wikis)

Although this raises another question:
SignableMessage can be string or { raw: Hex | ByteArray }. If a raw SignableMessage is passed along, I am not adding a prefix, because the expectation is that its already processed.

This is based on a large assumption I made around the interface. I am not certain this is the expectation from the interface. What do you think?

(to be clear, signing a message requires this prefix. If you sign without this prefix and try to verifyMessage it will fail)

});

beforeAll(async () => {
account = await getAwsKmsAccount({
Copy link
Member

Choose a reason for hiding this comment

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

So this will always hit a live KMS account? And is there any way to keep that address constant?

Copy link
Member Author

Choose a reason for hiding this comment

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

Same KMS keyId would get you the same address. One way to enforce this on a test would be to also expose TEST_AWS_KMS_EXPECTED_ADDRESS and verify it matches.

@gregfromstl gregfromstl added TS SDK Involves changes to the v5 TypeScript SDK. Feature Adds new functionality to the public API. labels Aug 27, 2024
Co-authored-by: greg <[email protected]>
Signed-off-by: Prithvish Baidya <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Adds new functionality to the public API. packages TS SDK Involves changes to the v5 TypeScript SDK.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants