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

Secure Wallet Encryption Implementation #41

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Project requirements
PROJECT_REQUIREMENTS.md
PROJECT_THESIS.md
web3_setup.md

# Dependencies
node_modules/
.env

# Build
dist/
build/

# IDE
.vscode/
.idea/

# Logs
*.log
npm-debug.log*

# OS
.DS_Store
2 changes: 1 addition & 1 deletion client/src/Transfer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function Transfer({ address, setBalance }) {
data: { balance },
} = await server.post(`send`, {
sender: address,
amount: parseInt(sendAmount),
amount: sendAmount,
recipient,
});
setBalance(balance);
Expand Down
76 changes: 45 additions & 31 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
## ECDSA Node

This project is an example of using a client and server to facilitate transfers between different addresses. Since there is just a single server on the back-end handling transfers, this is clearly very centralized. We won't worry about distributed consensus for this project.

However, something that we would like to incoporate is Public Key Cryptography. By using Elliptic Curve Digital Signatures we can make it so the server only allows transfers that have been signed for by the person who owns the associated address.

### Video instructions
For an overview of this project as well as getting started instructions, check out the following video:

https://www.loom.com/share/0d3c74890b8e44a5918c4cacb3f646c4

### Client

The client folder contains a [react app](https://reactjs.org/) using [vite](https://vitejs.dev/). To get started, follow these steps:

1. Open up a terminal in the `/client` folder
2. Run `npm install` to install all the depedencies
3. Run `npm run dev` to start the application
4. Now you should be able to visit the app at http://127.0.0.1:5173/

### Server

The server folder contains a node.js server using [express](https://expressjs.com/). To run the server, follow these steps:

1. Open a terminal within the `/server` folder
2. Run `npm install` to install all the depedencies
3. Run `node index` to start the server

The application should connect to the default server port (3042) automatically!

_Hint_ - Use [nodemon](https://www.npmjs.com/package/nodemon) instead of `node` to automatically restart the server on any changes.
# ECDSA Node

This project demonstrates a simple digital signature implementation using the Ethereum ECDSA (Elliptic Curve Digital Signature Algorithm) for secure transactions.

## New Features
- 🔒 Secure private key encryption using AES-256
- ✅ Wallet creation with automatic key encryption
- 💫 Transaction signing with encrypted keys
- 🛡️ Robust error handling and validation

## Security Features
- Private keys are never stored in plain text
- AES-256 encryption for key storage
- Signature verification for all transactions
- Proper error handling for security-related operations

## Prerequisites
- Node.js and npm installed
- Environment variables set up (see below)

## Environment Variables
Create a `.env` file in the server directory:
```env
ENCRYPTION_KEY=your-32-character-encryption-key
```

## Getting Started
1. Clone the repository
2. Install dependencies:
```bash
cd server
npm install
```

3. Set up your environment variables
4. Run the tests:
```bash
npx ts-node src/scripts/tests/wallet.test.ts
npx ts-node src/scripts/tests/wallet-edge-cases.test.ts
```

## Security Considerations
- Keep your ENCRYPTION_KEY secure and never commit it to version control
- Private keys are encrypted at rest
- All transactions require valid signatures
6 changes: 6 additions & 0 deletions server/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Server Configuration
PORT=3042
NODE_ENV=development

# Encryption (32+ character random string for AES-256)
ENCRYPTION_KEY=your-very-long-secure-encryption-key-here
21 changes: 21 additions & 0 deletions server/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
rules: {
// Add any custom rules here
},
};
1 change: 1 addition & 0 deletions server/.key-backup/key-1736479518737.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ENCRYPTION_KEY=2a17952d0f034dcac9c4633c40433fa8e591bd6e4dbf86f1e706ed60d11063de
5 changes: 5 additions & 0 deletions server/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "all"
}
Loading