Crypto is just a bunch of random numbers
So my partner made the mistake of pointing me to some discussion happening on Facebook about the worth of cryptocurrencies, where the terms ‘Tulip Bubble’, ‘energy utilization of a small nation’, and ‘scam’ were being bandied around.. now naturally I put my 2c’s in and wasted 2 days of my life trying to correct some of the tropes that I’m sure you’ve all heard before. (All the while trying to completely ignore the margin-based selloff that happened overnight wiping out about a weeks worth of gains for some of the coins I follow).
One phrase one of the people mentioned was ‘it’s just a bunch of random numbers’ which really got me in a tizzy on how far from the truth that statement is. It also dovetailed nicely into the work I’m doing on key generation on my Terra-Rust Client (which is still in it’s VERY early days, but hopefully it will allow people to have a CLI on windows as well as mac, & linux). because the only place where randomness is needed is in key generation (and a potentially some in signatures, but I digress). In fact it is really hard to generate random numbers on a blockchain. (and look at me, about to re-enter into the discussion group.. ugh)
And this all leads me to the point of the post. What exactly is ‘terravaloper12g4nkvsjjnl0t7fvq3hdcw7y8dc9fq69nyeu9q’ and why are things always asking me to write down a series of random words all the time?
I assume most of you know the concept of private & public keys, so I’m not going to bore you with my version. so let’s start with the random words.
The list of words you are presented with by most secure websites/crypto wallets is the place where randomness plays a key part. These words are combined with a passphrase to create a number called a seed, which I believe is 64 bytes long.
This seed is used to create the ‘root private key’. (usually seen as something with a ‘xprv’ prefix.
Now if you are using the ‘terracli’ command to recover your key, read the prompts carefully. The first one asks for your key, the next one asks for your passphrase, and the last one asks for your wallet password.
for example using the words
notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius
with no passphrase generates the public key
but with a passphrase generates
you will be in a world of pain when you need to recover it, and forget that you used a passphrase (or what it was)
now using the power of math. People way smarter than me came up with a technique where the same seed file can be used to generate lots of different keys for lots of different coin types. This is the ‘BIP32’ standard. when you see things like
This is derivation string which specifies the coin type (330 is LUNA), and the zeros represent the account and index. (which are usually zero, but you could increment the index if you want multiple unique keys for things, and allows things like your hardware wallet to store them easily).
These derivation path is combined and a new 64-byte number is generated.
This is split into 2 parts. called the secret and the chain. both of these are used as inputs to ECDSA and make up your private key, and from that the public key is generated.
I believe there is a way to identify keys that belong to the same root key, so if you want to some secret things, be careful.
The Public key(s)
Now for cosmos/tendermint keys the public key is then further refined into a address. The address is the RIPEMD160 of the SHA256 of the public key which ends up being 20 bytes long. This is used to generate all the non ‘pub’ keys that you can see.
This number, and the prefix is combined using Bech32, which adds a checksum to the end (so it’s harder to fat-finger an address). That’s why all the terra/terraoper numbers look very similar. they are except for the checksum.
There are 3 formats of addresses.
- The main account one (prefixed with ‘terra’)
- The validator / operator one (prefixed with ‘terraoper’ )
- The consensus one (prefixed with ‘terravalcons)
Each one has a corresponding public key, which is constructed in a similar fashion but using the public key, not the address.
and this is where i’m up too with my rust client. I would have been a bit further along, but someone on the internet was wrong… and you can’t just let that happen.