Skip to content

Conversation

@sirily11
Copy link
Contributor

@sirily11 sirily11 commented Nov 2, 2025

No description provided.

…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.
Copilot AI review requested due to automatic review settings November 2, 2025 18:09
Copy link

Copilot AI left a 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.

Comment on lines +572 to +598
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
}
Copy link

Copilot AI Nov 2, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +61 to +63
func GetStorage(storageType types.StorageClient, params ...any) (Storage, error) {
switch storageType {
case config.StorageClientTypeSQLite:
case types.StorageClientSQLite:
Copy link

Copilot AI Nov 2, 2025

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.

Copilot uses AI. Check for mistakes.
@sirily11 sirily11 merged commit 822608b into main Nov 3, 2025
1 check passed
@sirily11 sirily11 deleted the interaction-ui branch November 3, 2025 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants