SHA256 Hash Function

Publicado em: 30 Novembro 2020
no canal de: The Library Of Knowledge
384
2

Hi SUBSCRIBE for more insane value!

Hello and welcome to this course on building a blockchain and a cryptocurrency. By the end of this course, you will know how blockchains work at the core, and how cryptocurrencies like Bitcoin are implemented.

The next few videos introduce the core concepts of the Blockchain and cryptocurrencies. You will find them helpful if you want a more well-rounded understanding of the main features of both the blockchain and cryptocurrencies.

The code starts in the next section. But I recommend watching these introductory videos in order to see the main concepts that we’ll be focusing on when it comes to building blockchains and cryptocurrencies.

Alright, let’s get to it!

A hashing function generates a unique value for the combination of data attributes in the block. The hash for a new block is based on its own timestamp, the data it stores, and the hash of the block that came before it.

Install the `crypto-js` module which has the SHA256 (Secure Hashing Algorithm 256-bit) function:
$ npm i crypto-js --save

In block.js, require the sha256 from the `crypto-js` module at the top:
```
const SHA256 = require('crypto-js/sha256');
```

Then add a new static hash function to the Block class:
```
static hash(timestamp, lastHash, data) {
return SHA256(`${timestamp}${lastHash}${data}`).toString();
}
```

Now replace the ‘todo-hash’ stub in the `mineBlock` function:
```
const hash = Block.hash(timestamp, lastHash, data);
```

Check the command line - `npm run dev-test` should still be running. Notice the generated hash of the block.


Nesta página do site você pode assistir ao vídeo on-line SHA256 Hash Function duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário The Library Of Knowledge 30 Novembro 2020, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 384 vezes e gostou 2 espectadores. Boa visualização!