-
Notifications
You must be signed in to change notification settings - Fork 16
Feature: Implement KMS Wallet #510
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
Open
blueogin
wants to merge
17
commits into
master
Choose a base branch
from
feat/kms-wallet
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2f26fda
feat: integrate AWS KMS for enhanced wallet security
blueogin 60f5c68
feat: native eth transfer tx
blueogin 94bd40c
feat: native eth transfer tested
blueogin 8bd7419
feat: implement WETH deposit functionality in KMS transaction tests
blueogin 970cb67
chore: update .gitignore and add yalc.lock for package management
blueogin a05196e
fix: normalize wallet addresses in KMS and Web3 wallet implementations
blueogin c4fee86
chore: remove unused EthereumJS packages from package.json
blueogin fdfe82c
chore: clean up package-lock.json by removing unused EthereumJS depen…
blueogin b8f6dd2
fix: removed kms client
blueogin d3bf440
chore: remove unnecessary console log statements from Web3Wallet
blueogin 546d4c2
chore: update kms-ethereum-signing dependency to version 1.0.0 and ad…
blueogin 29dc67a
chore: simplify kms-ethereum-signing resolution in Jest configuration
blueogin 187dcd4
chore: remove kms-ethereum-signing path mapping from Jest configuration
blueogin 1b86d1c
chore: upgrade lockfile version
blueogin 6568bd1
chore: add @gooddollar/kms-ethereum-signing dependency and update rel…
blueogin 6816ae6
chore: update KMSWallet import to use @gooddollar/kms-ethereum-signing
blueogin 5b2bdb3
fix: add error handling for KMS wallet initialization in Web3Wallet
blueogin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,3 +17,5 @@ config/*/* | |
| test/jest-envs/* | ||
| uploads/* | ||
| .idea/ | ||
|
|
||
| .yalc/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,214 @@ | ||
| // @flow | ||
| import { | ||
| getEthereumAddress, | ||
| signTransaction as kmsSignTransaction, | ||
| signMessage as kmsSignMessage, | ||
| getPublicKey, | ||
| importKMSKey | ||
| } from '@gooddollar/kms-ethereum-signing' | ||
| import logger from '../../imports/logger' | ||
|
|
||
| const log = logger.child({ from: 'KMSWallet' }) | ||
|
|
||
| /** | ||
| * KMS Wallet Adapter | ||
| * Wraps eth-kms-signer functionality for use with Web3Wallet | ||
| */ | ||
| export class KMSWallet { | ||
| kmsKeys: Map<string, { keyId: string, address: string, region?: string }> | ||
| region: ?string | ||
|
|
||
| constructor(region?: string) { | ||
| this.kmsKeys = new Map() | ||
| this.region = region || process.env.AWS_REGION | ||
| } | ||
|
|
||
| /** | ||
| * Initialize KMS wallet with key IDs | ||
| * @param keyIds - Array of KMS key IDs or aliases | ||
| * @returns Promise resolving to array of addresses | ||
| */ | ||
| async initialize(keyIds: string[]): Promise<string[]> { | ||
| const addresses = [] | ||
|
|
||
| for (const keyId of keyIds) { | ||
| try { | ||
| const address = await getEthereumAddress(keyId, this.region) | ||
| this.kmsKeys.set(address.toLowerCase(), { | ||
| keyId, | ||
| address, | ||
| region: this.region | ||
| }) | ||
| addresses.push(address) | ||
| log.info('KMS wallet initialized', { keyId, address }) | ||
| } catch (error) { | ||
| log.error('Failed to initialize KMS key', { keyId, error: error.message }) | ||
| throw error | ||
| } | ||
| } | ||
|
|
||
| return addresses | ||
| } | ||
|
|
||
| /** | ||
| * Get KMS key ID for an address | ||
| * @param address - Ethereum address | ||
| * @returns KMS key ID or null | ||
| */ | ||
| getKeyId(address: string): ?string { | ||
| const keyInfo = this.kmsKeys.get(address.toLowerCase()) | ||
| return keyInfo ? keyInfo.keyId : null | ||
| } | ||
|
|
||
| /** | ||
| * Get region for an address | ||
| * @param address - Ethereum address | ||
| * @returns AWS region or null | ||
| */ | ||
| getRegion(address: string): ?string { | ||
| const keyInfo = this.kmsKeys.get(address.toLowerCase()) | ||
| return keyInfo ? keyInfo.region : null | ||
| } | ||
|
|
||
| /** | ||
| * Check if address is managed by KMS | ||
| * @param address - Ethereum address | ||
| * @returns boolean | ||
| */ | ||
| hasAddress(address: string): boolean { | ||
| return this.kmsKeys.has(address.toLowerCase()) | ||
| } | ||
|
|
||
| /** | ||
| * Get all addresses managed by KMS | ||
| * @returns Array of addresses | ||
| */ | ||
| getAddresses(): string[] { | ||
| return Array.from(this.kmsKeys.values()).map(k => k.address) | ||
| } | ||
|
|
||
| /** | ||
| * Sign a transaction using KMS | ||
| * @param address - Ethereum address to sign with | ||
| * @param transaction - Transaction parameters | ||
| * @returns Signed transaction hex string | ||
| */ | ||
| async signTransaction( | ||
| address: string, | ||
| transaction: { | ||
| to: string, | ||
| value?: string, | ||
| data?: string, | ||
| nonce?: number, | ||
| gasLimit?: string, | ||
| gasPrice?: string, | ||
| maxFeePerGas?: string, | ||
| maxPriorityFeePerGas?: string, | ||
| chainId: number, | ||
| rpcUrl?: string | ||
| } | ||
| ): Promise<string> { | ||
| const keyId = this.getKeyId(address) | ||
| if (!keyId) { | ||
| throw new Error(`No KMS key found for address: ${address}`) | ||
| } | ||
|
|
||
| const region = this.getRegion(address) | ||
|
|
||
| try { | ||
| if (transaction.rpcUrl != undefined && transaction.rpcUrl.includes('localhost')) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. write a comment why you do this |
||
| transaction = { | ||
| ...transaction, | ||
| maxFeePerGas: undefined | ||
| } | ||
| } | ||
| const signedTx = await kmsSignTransaction(keyId, transaction, region) | ||
| log.debug('Transaction signed with KMS', { address, keyId, chainId: transaction.chainId }) | ||
| return signedTx | ||
| } catch (error) { | ||
| log.error('Failed to sign transaction with KMS', { | ||
| address, | ||
| keyId, | ||
| error: error.message | ||
| }) | ||
| throw error | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Sign a message using KMS | ||
| * @param address - Ethereum address to sign with | ||
| * @param message - Message to sign | ||
| * @returns Signature hex string | ||
| */ | ||
| async signMessage(address: string, message: string): Promise<string> { | ||
| const keyId = this.getKeyId(address) | ||
| if (!keyId) { | ||
| throw new Error(`No KMS key found for address: ${address}`) | ||
| } | ||
|
|
||
| const region = this.getRegion(address) | ||
|
|
||
| try { | ||
| const signature = await kmsSignMessage(keyId, message, region) | ||
| log.debug('Message signed with KMS', { address, keyId }) | ||
| return signature | ||
| } catch (error) { | ||
| log.error('Failed to sign message with KMS', { | ||
| address, | ||
| keyId, | ||
| error: error.message | ||
| }) | ||
| throw error | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Import a private key into KMS | ||
| * @param privateKeyHex - Private key in hex format | ||
| * @param aliasName - Alias name for the KMS key | ||
| * @returns Promise resolving to key ID and address | ||
| */ | ||
| async importPrivateKey(privateKeyHex: string, aliasName: string): Promise<{ keyId: string, address: string }> { | ||
| try { | ||
| const result = await importKMSKey(privateKeyHex, aliasName, this.region) | ||
|
|
||
| const address = await getEthereumAddress(result.keyId, this.region) | ||
|
|
||
| this.kmsKeys.set(address.toLowerCase(), { | ||
| keyId: result.keyId, | ||
| address, | ||
| region: this.region | ||
| }) | ||
|
|
||
| log.info('Private key imported to KMS', { | ||
| aliasName, | ||
| keyId: result.keyId, | ||
| address | ||
| }) | ||
|
|
||
| return { keyId: result.keyId, address } | ||
| } catch (error) { | ||
| log.error('Failed to import private key to KMS', { | ||
| aliasName, | ||
| error: error.message | ||
| }) | ||
| throw error | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Get public key for an address | ||
| * @param address - Ethereum address | ||
| * @returns Public key hex string | ||
| */ | ||
| async getPublicKey(address: string): Promise<string> { | ||
| const keyId = this.getKeyId(address) | ||
| if (!keyId) { | ||
| throw new Error(`No KMS key found for address: ${address}`) | ||
| } | ||
|
|
||
| const region = this.getRegion(address) | ||
| return getPublicKey(keyId, region) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reduce duplicate code