Former End User Consultant, Current Software Developer, and a Master's degree holder in Data Science and Engineering.
In this section, we will take a look at installation of Node JS on different platforms. If node is already installed on your computer, you may skip this section and move to SHA256 JS module installation.
sudo apt-get install nodejs
This command will install node.js, along with NPM and many other dependent packages on your system.
Please note that you will not be able to use node.js until you restart your computer.
brew install node
Note: The instructions to install XCode and Homebrew can be found here
The next step after installing nodejs and npm is to check and verify the installed versions. You may run the following commands on any of the previously mentioned platforms:
node -v
npm -v
You can find more details about current versions on node.js official website.
To install a simple SHA-256 hash function for JavaScript which supports UTF-8 encoding, run the command:
npm install js-sha256
To use this SHA256 hashing algorithm in your program, open your javascript code and load the js-sha256
modules using the require()
function.
const sha256 = require("js-sha256").sha256;
Now, you can hash any string or variable by passing it as a parameter to sha256()
function. Example:
sha256('abc');
The result should be a 32 byte hash value equal to ‘ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad’
In our construction of a merkle tree, we are using double-SHA256 cryptographic hashing algorithm which is simply SHA256 applied twice.
You can compute the double-SHA256 hash value of any string or variable, using the following statement in Javascript.
> sha256(sha256('abc'));
The result should always be a 32 byte hash value equal to ‘dfe7a23fefeea519e9bbfdd1a6be94c4b2e4529dd6b7cbea83f9959c2621b13c’