Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thiagosouza/5f8ab44cf7ff4bc62bea9cbf39d31012 to your computer and use it in GitHub Desktop.
Save thiagosouza/5f8ab44cf7ff4bc62bea9cbf39d31012 to your computer and use it in GitHub Desktop.
[Bitcoin and Ethereum - Keys, Keypair, seeds, keystore and Addressess] #ethereum #bitcoin #keystore #seed
#Generating a usable Ethereum wallet and its corresponding keys
#https://kobl.one/blog/create-full-ethereum-keypair-and-address/
# Generate the private and public keys
openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout > Key
# Extract the public key and remove the EC prefix 0x04
cat Key | grep pub -A 5 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^04//' > pub
# Extract the private key and remove the leading zero byte
cat Key | grep priv -A 3 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^00//' > priv
#https://github.com/vkobel/ethereum-generate-wallet/blob/master/lib/x86-64/keccak-256sum
sudo chmod a+x keccak-256sum
./keccak-256sum -x -l pub
# Generate the hash and take the address part
cat pub | ./keccak-256sum -x -l | tr -d ' -' | tail -c 41 > address
# (Optional) import the private key to geth
geth account import priv
#Generating a usable Ethereum wallet and its corresponding keys
#https://kobl.one/blog/create-full-ethereum-keypair-and-address/
# Generate the private and public keys
openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout > Key
# Extract the public key and remove the EC prefix 0x04
cat Key | grep pub -A 5 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^04//' > pub
# Extract the private key and remove the leading zero byte
cat Key | grep priv -A 3 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^00//' > priv
#https://github.com/vkobel/ethereum-generate-wallet/blob/master/lib/x86-64/keccak-256sum
sudo chmod a+x keccak-256sum
./keccak-256sum -x -l priv
# Generate the hash and take the address part
cat pub | ./keccak-256sum -x -l | tr -d ' -' | tail -c 41 > address
# (Optional) import the private key to geth
geth account import priv
//cat ~/.ethereum/keystore/UTC--<created_date_time>-- 008aeeda4d805471df9b2a5b0f38a0c3bcba786b
{
"crypto" : {
"cipher" : "aes-128-ctr",
"cipherparams" : {
"iv" : "83dbcc02d8ccb40e466191a123791e0e"
},
"ciphertext" : "d172bf743a674da9cdad04534d56926ef8358534d458fffccd4e6ad2fbde479c",
"kdf" : "scrypt",
"kdfparams" : {
"dklen" : 32,
"n" : 262144,
"r" : 1,
"p" : 8,
"salt" : "ab0c7876052600dd703518d6fc3fe8984592145b591fc8fb5c6d43190334ba19"
},
"mac" : "2103ac29920d71da29f15d75b4a16dbe95cfd7ff8faea1056c33131d846e3097"
},
"id" : "3198bc9c-6672-5ab3-d995-4942343ae5b6",
"version" : 3
}
//What is an Ethereum keystore file?
//https://medium.com/@julien.maffre/what-is-an-ethereum-keystore-file-86c8c5917b97
//npm install -S bn.js elliptic js-sha3
var EC = require('elliptic').ec;
var BN = require('bn.js');
var ec = new EC('secp256k1');
const keccak256 = require('js-sha3').keccak256;
// console.log("PK::"+pk);
pk = '00000000000000000000000000000001';
pk = '0000000000000000000000000000000000000000000000000000000000000001';
pk = '1';
pk = new BN('1');
var privateKey=Buffer.alloc(32, 0);
privateKey[31]=1;
pk = privateKey.toString('hex');
//example with private key generated with openssl lib
//openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout > Key
//cat Key | grep priv -A 3 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^00//' > priv
//(priv = '868f70c2c5760aaffd559157c792816e3ef10fc8610a567abbba6c4a9bc7f1c6')
pk = '868f70c2c5760aaffd559157c792816e3ef10fc8610a567abbba6c4a9bc7f1c6';
var G = ec.g; // Generator point (fixed)
//<EC Point x: 79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 y: 483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8>
var pubPoint = G.mul(pk); // EC multiplication to determine public point
var x = pubPoint.getX().toBuffer(); //32 bit x co-ordinate of public point
var y = pubPoint.getY().toBuffer(); //32 bit y co-ordinate of public point
var publicKey = Buffer.concat([x,y]);
console.log("pub key::" + publicKey.toString('hex'));
const address = keccak256(publicKey); // keccak256 hash of publicKey
const buf2 = Buffer.from(address, 'hex');
console.log("Ethereum Adress:::"+"0x"+buf2.slice(-20).toString('hex')); // take last 20 bytes as ethereum adress
//Understanding the concept of Private Key, Public Key and Address in Ethereum Blockchain
//https://etherworld.co/2017/11/17/understanding-the-concept-of-private-key-public-key-and-address-in-ethereum-blockchain/
#Secp256k1
#https://en.bitcoin.it/wiki/Secp256k1
#Endereços e Carteiras
#https://btcparaprogramadores.marcoagner.org/enderecos-e-carteiras.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment