私人区块链

  • h7_331155
    了解作者
  • 18.9KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-15 02:23
    上传日期
私人区块链应用 您以区块链开发人员的身份开始旅程,此项目可让您证明您已熟悉区块链平台的基本概念。 像这样的概念:-区块-区块链-钱包-区块链身份-存在证明 您是否需要描述区块链框架中一些最重要的组件,为什么不呢? 也实施。 在这个项目中,您将具有已经设置好的REST Api的样板代码,以展示您将在私有区块链中实现的一些功能。 您将解决实施此私有区块链应用程序的什么问题? 您的雇主正在尝试对如何在公司中实施区块链应用程序进行概念测试。 他是天文学迷,他将大部分的业余时间都花在搜寻天空中的恒星上,这就是为什么他想要创建一个测试应用程序以允许他注册恒星,他的其他一些朋友也可以注册恒星,但是确保应用程序知道谁拥有每颗星星。 雇主描述将在申请中实施的流程是什么? 当我们运行应用程序时,该应用程序将创建一个创世纪模块。 用户将请求应用程序发送要使用电子钱包签名的消息,并以此方式验证钱包地址上的
private-blockchain-main.zip
  • private-blockchain-main
  • .gitignore
    20B
  • BlockchainController.js
    4.9KB
  • app.js
    1.5KB
  • package.json
    539B
  • package-lock.json
    26.7KB
  • src
  • blockchain.js
    8.4KB
  • block.js
    3.7KB
  • README.md
    11.6KB
内容介绍
# Private Blockchain Application You are starting your journey as a Blockchain Developer, this project allows you to demonstrate that you are familiarized with the fundamentals concepts of a Blockchain platform. Concepts like: - Block - Blockchain - Wallet - Blockchain Identity - Proof of Existance Are some of the most important components in the Blockchain Framework that you will need to describe and also why not? Implement too. In this project you will have a boilerplate code with a REST Api already setup to expose some of the functionalities you will implement in your private blockchain. ## What problem will you solve implementing this private Blockchain application? Your employer is trying to make a test of concept on how a Blockchain application can be implemented in his company. He is an astronomy fans and he spend most of his free time on searching stars in the sky, that's why he would like to create a test application that will allows him to register stars, and also some others of his friends can register stars too but making sure the application know who owned each star. ### What is the process describe by the employer to be implemented in the application? 1. The application will create a Genesis Block when we run the application. 2. The user will request the application to send a message to be signed using a Wallet and in this way verify the ownership over the wallet address. The message format will be: `<WALLET_ADRESS>:${new Date().getTime().toString().slice(0,-3)}:starRegistry`; 3. Once the user have the message the user can use a Wallet to sign the message. 4. The user will try to submit the Star object for that it will submit: `wallet address`, `message`, `signature` and the `star` object with the star information. The Start information will be formed in this format: ```json "star": { "dec": "68° 52' 56.9", "ra": "16h 29m 1.0s", "story": "Testing the story 4" } ``` 5. The application will verify if the time elapsed from the request ownership (the time is contained in the message) and the time when you submit the star is less than 5 minutes. 6. If everything is okay the star information will be stored in the block and added to the `chain` 7. The application will allow us to retrieve the Star objects belong to an owner (wallet address). ## What tools or technologies you will use to create this application? - This application will be created using Node.js and Javascript programming language. The architecture will use ES6 classes because it will help us to organize the code and facilitate the maintnance of the code. - The company suggest to use Visual Studio Code as an IDE to write your code because it will help you debug the code easily but you can choose the code editor you feel confortable with. - Some of the libraries or npm modules you will use are: - "bitcoinjs-lib": "^4.0.3", - "bitcoinjs-message": "^2.0.0", - "body-parser": "^1.18.3", - "crypto-js": "^3.1.9-1", - "express": "^4.16.4", - "hex2ascii": "0.0.3", - "morgan": "^1.9.1" Remember if you need install any other library you will use `npm install <npm_module_name>` Libraries purpose: 1. `bitcoinjs-lib` and `bitcoinjs-message`. Those libraries will help us to verify the wallet address ownership, we are going to use it to verify the signature. 2. `express` The REST Api created for the purpose of this project it is being created using Express.js framework. 3. `body-parser` this library will be used as middleware module for Express and will help us to read the json data submitted in a POST request. 4. `crypto-js` This module contain some of the most important cryotographic methods and will help us to create the block hash. 5. `hex2ascii` This library will help us to **decode** the data saved in the body of a Block. ## Understanding the boilerplate code The Boilerplate code is a simple architecture for a Blockchain application, it includes a REST APIs application to expose the your Blockchain application methods to your client applications or users. 1. `app.js` file. It contains the configuration and initialization of the REST Api, the team who provide this boilerplate code suggest do not change this code because it is already tested and works as expected. 2. `BlockchainController.js` file. It contains the routes of the REST Api. Those are the methods that expose the urls you will need to call when make a request to the application. 3. `src` folder. In here we are going to have the main two classes we needed to create our Blockchain application, we are going to create a `block.js` file and a `blockchain.js` file that will contain the `Block` and `BlockChain` classes. ### Starting with the boilerplate code: First thing first, we are going to download or clone our boilerplate code. Then we need to install all the libraries and module dependencies, to do that: open a terminal and run the command `npm install` **( Remember to be able to work on this project you will need to have installed in your computer Node.js and npm )** At this point we are ready to run our project for first time, use the command: `node app.js` You can check in your terminal the the Express application is listening in the PORT 8000 ## What do I need to implement to satisfy my employer requirements? 1. `block.js` file. In the `Block` class we are going to implement the method: `validate()`. /** * The `validate()` method will validate if the block has been tampered or not. * Been tampered means that someone from outside the application tried to change * values in the block data as a consecuence the hash of the block should be different. * Steps: * 1. Return a new promise to allow the method be called asynchronous. * 2. Save the in auxiliary variable the current hash of the block (`this` represent the block object) * 3. Recalculate the hash of the entire block (Use SHA256 from crypto-js library) * 4. Compare if the auxiliary hash value is different from the calculated one. * 5. Resolve true or false depending if it is valid or not. * Note: to access the class values inside a Promise code you need to create an auxiliary value `let self = this;` */ 2. `block.js` file. In the `Block` class we are going to implement the method: `getBData()`. /** * Auxiliary Method to return the block body (decoding the data) * Steps: * * 1. Use hex2ascii module to decode the data * 2. Because data is a javascript object use JSON.parse(string) to get the Javascript Object * 3. Resolve with the data and make sure that you don't need to return the data for the `genesis block` * or Reject with an error. */ 3. `blockchain.js` file. In the `Blockchain` class we are going to implement the method: `_addBlock(block)`. /** * _addBlock(block) will store a block in the chain * @param {*} block * The method will return a Promise that will resolve with the block added * or reject if an error happen during the execution. * You will need to check for the height to assign the `previousBlockHash`, * assign the `timestamp` and the correct `height`...At the end you need to * create the `block hash` and push the block into the chain array. Don't for get * to update the `this.height` * Note: the symbol `_` in the method name indicates in the javascript convention * that this method is a private method. */ 4. `blockchain.js` file. In the `Blockchain` class we are going to implement the method: `requestMessageOwnershipVerification(address)` /** * The requestMessageOwnershipVerification(address) method * will allow you to request a message that you will use to * sign it with your Bitcoin Wallet (Electrum or Bitcoin Core) * This is the first step before submit your Block. * The method return a Promis
评论
    相关推荐
    • 区块链
      区块链Python 专案 课堂项目的第1部分 基本设置和工作证明(basic_block_gp) 第1部分带回家的项目 客户端矿工(client_mining_p) 课堂项目的第二部分 基本交易(basic_transactions_gp) 第2部分带回家的项目 ...
    • 区块链
      区块链 运行权限证明区块链 权限证明(PoA)算法通常用于私有区块链网络,因为它需要预先批准或投票批准可以批准交易(封签)的账户地址。 由于必须批准帐户,因此我们将生成两个具有新帐户地址的新节点,这些地址将...
    • 区块链
      区块链
    • 区块链白皮书
      区块链白皮书合集,内容比较全,2018新版。区块链白皮书合集,内容比较全,2018新版。
    • 区块链
      区块链
    • 区块链
      区块链
    • 区块链技术
      .希望进行区块链开发的程序员。 ·希望投资或参与区块链项目的人员。 ·对区块链感兴趣的爱好者
    • 区块链
      blochchain_prot 该项目基于hyperledger fabric 2.1版本,有关详细说明,请访问 。 您也可以在该手册。
    • 区块链
      区块链Python 专案 课堂项目的第1部分 基本设置和工作证明(basic_block_gp) 第1部分带回家的项目 客户端矿工(client_mining_p) 课堂项目的第二部分 基本交易(basic_transactions_gp) 第2部分带回家的项目 ...
    • SIM800C_MQTT.rar
      使用SIM800C模块,使用MQTT协议,连接中国移动onenet平台,能实现数据的订阅、发布、存储等