-
Notifications
You must be signed in to change notification settings - Fork 1
Generating a Metahash address
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.
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.
These are the steps to follow to create your own MetaHash address.
- Take part of the public key that equals to 65 bytes, where first byte is 0x04, next 32 bytes correspond to the X-coordinate and following 32 bytes to the Y-coordinate.
openssl ecparam -genkey -name secp256k1 -out test.pem
openssl ec -in test.pem -pubout -outform DER|tail -c 65|xxd -p -c 65 > btc_test.pub
- Perform SHA-256 hash on the public key.
cat btc_test.pub | xxd -r -p | openssl dgst -sha256
(stdin)= 37ace8da185aaa3f7505f41647b52a2d8a449de6b71fced8636acf86bbe65678
- Public key hash received on previous step is now hashed using cryptographic RIPEMD-160 hash function, 0x0 is added in front.
echo -e 37ace8da185aaa3f7505f41647b52a2d8a449de6b71fced8636acf86bbe65678 | xxd -r -p | openssl dgst -rmd160
(stdin)= 84eba56e4d3aaff9ab6e43dada7ad861750fab32
0084eba56e4d3aaff9ab6e43dada7ad861750fab32
- SHA-256 hash is calculated on the result of previous step.
echo -e 0084eba56e4d3aaff9ab6e43dada7ad861750fab32 | xxd -r -p | openssl dgst -sha256
(stdin)= fb17d569e0672a12ae2f85535b035bdd5011d57e7c0ad5be1e60c5f50945fb91
- Another SHA-256 hash performed on value from Step 4. Only first 4 bytes of resulting hash are used.
echo -e fb17d569e0672a12ae2f85535b035bdd5011d57e7c0ad5be1e60c5f50945fb91 | xxd -r -p | openssl dgst -sha256
2f5e349e7f81f46ce037ccfe8ed5a793f8d9aac90c34c48fda050b079bd780c2
- These 4 bytes from last step added to RIPEMD-160 hash (value from step 3) with prefix 0x. Congrats, this is the address!
0x0084eba56e4d3aaff9ab6e43dada7ad861750fab322f5e349e
For more details about Metahash address generation, please see examples: