阅读bitcoin白皮书bitcoin-paper (bitcoin-paper(中文版)),学习区块链知识,用JavaScript简单实现了区块链的一些概念(Some concepts of blockchain are simply implemented in JavaScript to learn blockchain knowledge)
- 区块链的验证(JavaScript implementation of blockchain to prevent data from being tampered with)
- 工作量证明机制的简单实现(Simple implementation of proof-of-work mechanism)
- 转账(Transaction)
- 挖矿的简单实现(Mine)
- 生成密钥对(Generate keyPair)
const ecLib = require("elliptic").ec;
const ec = new ecLib("secp256k1"); // curve name
const sha256 = require("crypto-js/sha256");
// 生成密钥对
const keyPair = ec.genKeyPair();
// 拿到 hex string 格式的私钥和公钥
console.log("privateKey", keyPair.getPrivate("hex"));
console.log("publicKey", keyPair.getPublic("hex"));
const myCoin = new chain();
const transaction = new Transaction("addrSender1", "addrReceiver1", 10);
myCoin.addTransaction(transaction);
myCoin.mineTransactionPool('addr3');
- 交易签名(Sign transactions.)