-
Notifications
You must be signed in to change notification settings - Fork 1
Getting started with Metahash network
This page describes public and private keys generation, getting Metahash address, and also will get you familiar with digital signature and its verification. We hope you find this documentation easy to follow.
MetaHash is a next-generation network based on Blockchain 2.0 technology for the exchange of digital assets and management of decentralized applications. In order to perform transactions and store your assets in MetaHashCoin (MHC) you need to have digital wallet based on asymmetric encryption.
Asymmetric encryption is a cryptographic system that uses a pair of asymmetric keys to encrypt and decrypt data. There are public and private keys. Public key is used to encrypt a message, and private key is used for decryption. When performing transactions, all data is also signed with a private key. To start using the Metahash network you need to generate address, keys and signature.
Private key generation is the first step towards getting the address, that will allow you to receive online payments and make transfers within Metahash network. Private key allows you to decrypt messages encrypted with public key and verifies identity, proving you are authentic address owner.
Private key is generated using a cryptographic algorithm on the elliptic curves secp256r1 (OpenSSL: secp256k1 (prime256v1)).
Generate private key:
openssl ecparam -genkey -name secp256k1 -out test.pem
View private key:
openssl ec -in test.pem -outform DER | xxd -p
read EC key
writing EC key
30740201010420958392620fc5683c93fc2292c3f88471f859d0b7197d250ec5a544a275a01f26a00706052b8104000aa14403420004b842e62cad329b7a96338e52458594793efcbad337f0d1eba09132d56dcf6d52c7e828e5108f61981fbe0e5d9d5cc39730250ed34521565672d5d68c2fa33f09
Public key is generated on private key with Elliptic Curve Cryptography algorithm and SHA-256 hash function. Public key may be widely distributed within Metahash network, while the private key is known only to its proprietor. Public key is used to encrypt message.
Generate public key:
openssl ec -in test.pem -pubout -out test.pub
View public key:
openssl ec -in test.pem -pubout -outform DER | xxd -p
read EC key
writing EC key
3056301006072a8648ce3d020106052b8104000a03420004b842e62cad329b7a96338e52458594793efcbad337f0d1eba09132d56dcf6d52c7e828e5108f61981fbe0e5d9d5cc39730250ed34521565672d5d68c2fa33f09
Next step is to get the Metahash address using recently generated public and private keys. Address is a user identifier in Metahash network which is required to perform transactions. Each user of the network can have an infinite number of addresses that are stored in their wallet to be used for transactions. For more details about Metahash address generation, please see Generating-a-Metahash-address
Transaction means transferring MHC between two addresses. Transactions inside the MetaHash network are conducted only if confirmed by the digital signature. The data is signed with a private key. Combined with the public key, digital signature confirms that the transaction was created by the real owner of MetaHash address.
Example of data signing: The text "test" must be signed with private key test.pem. Below you can see the examples of signing a text file or a text directly:
echo -e test | openssl dgst -sha256 -sign test.pem > test.sign
or
openssl dgst -sha256 -sign test.pem test.txt > test.sign
where
cat test.txt
test
As a result we receive the text signed with private key:
cat test.sign | xxd -p
30450220257fd50e5790871533bd2578212f874e06ae23ad4361292846f7
e3384b9ec0a40221009ef06d0021bffabacb8d832b77cd60af8d63255f1b
72ad6edf265350c046dbd0
Signed text, source text and public key (in the example below, it is defined as test.pub) go through the verification process.
openssl dgst -sha256 -verify test.pub -signature test.sign test.txt
Verified OK
Verification has been completed successfully.