-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add wallet management ui #2
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
Conversation
…red logging - Introduced a new logging system in `internal/log/` using `zerolog` and `lumberjack` for structured logging and file rotation. - Added comprehensive usage documentation in `internal/log/USAGE.md`. - Implemented logging in various application components, including error handling and storage management. - Created tests for the logging functionality to ensure reliability and correctness.
fb1a34a to
dc19012
Compare
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.
Pull Request Overview
This PR implements comprehensive wallet management functionality for a smart contract CLI, including:
- Database models and queries for EVM wallet storage
- Wallet service layer with private key/mnemonic import and generation capabilities
- Secure storage utilities and logger infrastructure
- BIP39 mnemonic support and HD wallet derivation
- Error handling improvements and new error codes
Reviewed Changes
Copilot reviewed 31 out of 35 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/contract/evm/wallet/service.go | New wallet service with import/generate/CRUD operations |
| internal/contract/evm/storage/models/evm/wallet.go | Wallet database model with secure storage key helpers |
| internal/contract/evm/storage/sql/queries/wallet_queries.go | GORM queries for wallet database operations |
| internal/contract/evm/storage/sql/sqlite.go | SQLite implementation of wallet storage interface |
| internal/contract/evm/storage/sql/storage.go | Storage interface with wallet methods |
| internal/storage/secure.go | Renamed Unlock to TestPassword method |
| internal/utils/storage.go | Utility for retrieving secure storage from shared memory |
| internal/log/logger.go | New logger implementation with file rotation support |
| internal/errors/errors.go & code.go | New storage error codes and constructors |
| internal/config/storage.go & shared_memory_keys.go | Configuration keys reorganization |
| tools/tools.go | Mock generation directives for testing |
| go.mod/go.sum | Added dependencies for BIP39, zerolog, lumberjack, mock |
| docs/* | Comprehensive design documentation for wallet/endpoint/contract/ABI management |
| ~/smart_contract_cli | SQLite database file (should not be committed) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func derivePrivateKey(seed []byte, path accounts.DerivationPath) (*ecdsa.PrivateKey, error) { | ||
| // For Ethereum, we use the master key derived from the seed | ||
| // This is a simplified approach - for production, use a proper BIP32 library | ||
|
|
||
| // For now, we'll use a simplified approach: just use the seed directly for the first account | ||
| // m/44'/60'/0'/0/0 -> use the seed with the account index | ||
|
|
||
| // Get the account index (last element in path) | ||
| if len(path) < 5 { | ||
| return nil, fmt.Errorf("invalid derivation path: expected at least 5 elements") | ||
| } | ||
|
|
||
| // For standard Ethereum path m/44'/60'/0'/0/N, use the seed + account index | ||
| // This is a simplified version - in production you'd use full BIP32 derivation | ||
| accountIndex := path[len(path)-1] | ||
|
|
||
| // Derive using crypto.Keccak256 | ||
| derivedSeed := crypto.Keccak256(seed, []byte(fmt.Sprintf("%d", accountIndex))) | ||
|
|
||
| // Create private key from derived seed | ||
| privateKey, err := crypto.ToECDSA(derivedSeed) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to create private key: %w", err) | ||
| } | ||
|
|
||
| return privateKey, nil | ||
| } |
Copilot
AI
Nov 2, 2025
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.
The HD wallet derivation implementation is non-standard and insecure. It uses Keccak256(seed + accountIndex) instead of proper BIP32 hierarchical key derivation. This means derived keys are not compatible with standard wallets and may have security vulnerabilities. Use a proper BIP32 library (e.g., github.com/tyler-smith/go-bip32) for production.
| func GetStorage(storageType types.StorageClient, params ...any) (Storage, error) { | ||
| switch storageType { | ||
| case config.StorageClientTypeSQLite: | ||
| case types.StorageClientSQLite: |
Copilot
AI
Nov 2, 2025
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.
[nitpick] The function uses variadic 'any' parameters which loses type safety. Consider using a structured config object or specific typed parameters to make the function signature clearer and catch errors at compile time.
dc19012 to
d5fe60f
Compare
No description provided.