Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
121 changes: 121 additions & 0 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite --host 0.0.0.0",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"axios": "^0.27.2",
"ethereum-cryptography": "^1.1.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3"

services:
node-server:
tty: true
build:
context: .
dockerfile: docker/nodejs/Dockerfile
ports:
- 3042:3042
- 5173:5173
restart: unless-stopped
volumes:
- ./:/app

5 changes: 5 additions & 0 deletions docker/nodejs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node:18.12
LABEL name="Fazal-E-Rabbi" email="[email protected]"

WORKDIR /app
EXPOSE 3042 5173
19 changes: 13 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,34 @@ This project is an example of using a client and server to facilitate transfers
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
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
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!
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.

### Private keys:

1. cdb9e4375c44d33c80ee6c09f71ec3040fab2bb078a70e829e1193efb1aa1551
2. 4791bdd76e771b729152b4464fca807d2e8ad55cb6a15601ea21e3b80a6f0535
3. 2a51b21a31600e1342cf1d258d911aab314c7f01c9ba753eabc24021089d9dc2
32 changes: 20 additions & 12 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
const express = require("express");
const app = express();
const cors = require("cors");
const { getAddress } = require("./scripts/cryptography");
const port = 3042;

app.use(cors());
app.use(express.json());

const balances = {
"0x1": 100,
"0x2": 50,
"0x3": 75,
"3b01872578dc3a74bbaafa4ded424b54cefc7883": 100,
"5342f7810d21bb46fb2093e77fc3cf9a0b4a8b20": 50,
"50aeafd07d1cf0bc3fa3665e94e4a7e91fd70d46": 75,
};

app.get("/balance/:address", (req, res) => {
const { address } = req.params;
app.get("/balance/:privateKey", async (req, res) => {
const { privateKey } = req.params;
const message = "Get Blanace";
const address = await getAddress(message, privateKey);
console.log("address: ", address);

const balance = balances[address] || 0;
res.send({ balance });
});

app.post("/send", (req, res) => {
app.post("/send", async (req, res) => {
const { sender, recipient, amount } = req.body;

setInitialBalance(sender);
setInitialBalance(recipient);
const senderAddress = await getAddress("Get Balance", sender);
const recipientAddress = await getAddress("Get Balance", recipient);

if (balances[sender] < amount) {
setInitialBalance(senderAddress);
setInitialBalance(recipientAddress);

if (balances[senderAddress] < amount) {
res.status(400).send({ message: "Not enough funds!" });
} else {
balances[sender] -= amount;
balances[recipient] += amount;
res.send({ balance: balances[sender] });
balances[senderAddress] -= amount;
balances[recipientAddress] += amount;
res.send({ balance: balances[senderAddress] });
}
});

Expand Down
Loading