https://github.com/kenken64/merlioncoin
Simple Blockchain written in Javascript
https://github.com/kenken64/merlioncoin
nodejs websocket
Last synced: about 2 months ago
JSON representation
Simple Blockchain written in Javascript
- Host: GitHub
- URL: https://github.com/kenken64/merlioncoin
- Owner: kenken64
- Created: 2018-07-17T07:41:05.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-31T04:27:28.000Z (almost 8 years ago)
- Last Synced: 2025-04-24T03:39:30.254Z (about 1 year ago)
- Topics: nodejs, websocket
- Language: JavaScript
- Homepage:
- Size: 8.67 MB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## The Merlion Stable Coin
```
npm i nodemon --save-dev
npm i jest --save-dev
```
Runtime libraries
```
npm i crypto-js --save
npm i express --save
```
## Node 1
```
npm run dev
```
## Node 2
```
HTTP_PORT=3002 P2P_PORT=5002 PEERS=ws://localhost:5001 npm run dev
```
## Node 3
```
HTTP_PORT=3003 P2P_PORT=5003 PEERS=ws://localhost:5001,ws://localhost:5002 npm run dev
```
## Proof of work
(PoW) system (or protocol, or function) is an economic measure to deter denial of service attacks and other service abuses such as spam on a network by requiring some work from the service requester, usually meaning processing time by a computer.
* Any peer can replace the chain
* POW makes it expensive to generate corrupt chains
* Is quite manageable to submit one block rather than the entire chain.
Bitcoin POW uses hashcash created since 1997 it is used to prevent for email spamming
Difficulty = 6
Hash = 000000haxi2910jasdfsjfd
Generate the hash until all the leading zeroes macthes.
A nonce value adjust new hash is generated
The computation work is 'mining'
The difficulty sets a rate of mining
Bitcoin sets the rate to new block approximately around every 10 minutes.
## 51% attack
* Dishonest miner owns the 51% of the network power
* A 51% attack for bitcoin would be more than $6 billion
Dynamic Block adjust difficulty
* lastBlock timestamp + mine rate > currentTime then we know is too easy increase difficulty
+1 else -1
## Wallets, Keys and transaction
### What is a wallet?
* Have a balance field
* Store keys (Private Keys and Public Keys) Everyone sees the Public Keys
Private Key - used to generate signatures
Public Key - used to verify the signatures and also public account address
### Transactions
* Input of the transaction details
** timestamp,balance and public key
* Output chain as transactions
### Digital Signatures
* Create wallet
* Elliptic-curve cryptography (ECC) is an approach to public-key cryptography based on the algebraic structure of elliptic curves over finite fields. ECC requires smaller keys compared to non-ECC cryptography (based on plain Galois fields) to provide equivalent security.
* Install npm i elliptic --save
Mid 1980s
y^{2}=x^{3}+ax+b,\,
https://www.youtube.com/watch?v=dCvB-mhkT0w