How a Litecoin address is created
A Litecoin address is in some ways like an E-Mail address. It is used to interact with other people. However, there are some differences.
While you might only own one or two E-Mail addresses, you would own several different Litecoin addresses. For security reasons, a lot of users of cryptocurrencies have a unique address per transaction. You can create “new addresses” using Litecoin core, an account at an exchange or an online wallet.
In general, a Litecoin address is an identifier made up of alphanumeric characters. In total addresses contain 26–35 characters. While most addresses contain 34 characters there is a significant percentage containing only 33 characters.
The reason for these length differences is that each address stands for a number. The shorter addresses starting with zeros, which can be omitted while encoding, are still being accepted as a valid address. This is possible because several of the characters of a Litecoin address are used as a checksum so that typographical errors are found and rejected.
Addresses consist of random digits and uppercase and lowercase letters. To prevent visual ambiguity, the uppercase letter “O”, uppercase letter “I”, lowercase letter “l” and the number “0” are not used.
From private key to public key
The creation of a Litecoin address starts with the private key. It is a randomly generated string of numbers and letters and it is used to create a corresponding public key. Even if the public key is derived from the private key, it would take the most powerful supercomputer many trillion years to crack the private key.
You can compare the public key with a coordinate system with an x- and y-axis. The point where the two graphs meet, is the point where the private key is located on the cryptographic curve. In addition to that, there are two ways to store the public key: Compressed and uncompressed. An uncompressed public key includes both coordinates, while a compressed public key only includes one coordinate. Let us use the coordinate system again. Knowing the exact position on the x-axis is enough to compute the corresponding value for y.
Note that the public key is not the Litecoin address per se. The public key needs to be hashed to create a valid address. Hashing is a process used to shorten data with the help of cryptographic methods. The outcome will always be the same hash as long as the input stays the same, but it is impossible to derive the input only knowing the output.
While doing the same thing compressed and uncompressed keys have structural differences. This is why you will get two completely different outputs when you hash them. It also leads to different addresses.
Pay to public key hash aka Litecoin addresses with prefix “L”
From the beginning, transactions between wallets used the “Pay to Public Key Hash” (P2PKH) method. These hashes are created by running the public key through several hash algorithms.
Since Litecoin is a fork of Bitcoin it used to have the same format as Bitcoin for wallet addresses by default. This meant that people could mistake LTC addresses for BTC addresses and vice versa. When they tried to transfer funds to a wallet which did not support the currency they were sending, the funds were lost and could not be returned. To cope with that, LTC changed the “1” to an “L”, so now all addresses starting with an “L” are P2PKH Litecoin addresses. P2PKH testnet addresses start with “m” or “n”.
If someone wants to pay out coins, they sign with the private key, but they will also have to provide the public key. To check whether the payment is valid, the address must be generated again from the public key. The script verifies that by checking whether the provided public key hash matches the hash in the scriptPubKey script. After that, it checks the signature against the public key.
However, creating an address from the public key has two advantages. First of all, it is more convenient because the address is shorter than a non-hashed key and much more user-friendly. Secondly, it is also safer because the public key is only revealed when the coins are issued again at an address.
Pay to script hash aka Litecoin addresses with prefix “3” and “M”
Pay to script hash (P2SH) is more difficult to understand than the P2PKH method. It helps to keep in mind that payments do not have a recipient per se, but define a rule of how the transferred coins can be spent.
Until the development of P2SH, the sender of a payment defined this condition by providing an address. With P2SH this has been reversed: The recipient defines a rule (the script) and forms the hash from it. The sender can simply pay for a hash and the recipient can receive the coins the moment the script from which the specified hash is derived is submitted.
P2SH was introduced to enable users to make transactions easier, which are signed by more than one person, a process called multisig. These multisig transactions could also be made using P2PKH but they have a major disadvantage, that P2SH can solve. The receiver would need to send the whole transaction script including all addresses and public keys to the sender of the coins.
This can become very complex, especially when many participants are involved. With P2SH, the most complex multisig transactions would be no more complex than the simplest transaction using P2PKH.
It is possible to send Litecoins to an address that is secured in various ways without knowing anything about how the security is set up. The recipient might need the signatures of several people, or use a password, or fulfill other unique requirements. With P2PKH the sender does not have to do any of this anymore.
The P2SH addresses have the same format as the P2PKH addresses but start with a “3” or an “M”. Since Litecoin is technically a fork of Bitcoin, they shared the same prefix “3” in the beginning. To make it more convenient for the user and to prevent errors, the Litecoin community agreed to change the “3” to an “M”. This was done by altering the hashing algorithm. On testnet the equivalent of addresses using the prefix “3”, start with “2” and with “Q” instead of the “M”.
To easily convert between the standard 3-prefix P2SH address format and the M-prefix, you can use the open-source tool provided by the Litecoin Foundation. If you have security concerns, you can also view the source code of the tool.
P2WPKH aka Litecoin addresses with prefix “ltc1”
P2SH addresses also allow the processing of other scripts besides multisig. For example, the SegWit protocol upgrade was introduced via the P2SH addresses.
SegWit uses a new process, P2WPKH, which stands for “Pay To Witness Public Key Hash”. Here, the payment is not transferred to the public key, but to the public key hash that accompanies the outsourced signature. By hashing this script itself, it can be part of a P2SH address.
This has the advantage that every existing wallet can send to SegWit addresses. This can be done because a SegWit address will look exactly like a P2SH transaction. An observer of the blockchain can only distinguish the SegWit addresses from the already known P2SH addresses when the coins on them are issued.
However, it has the disadvantage that it is more complex. Therefore, another address format was introduced at the same time. It implements P2WPKH natively instead of pressing it into a P2SH address.
These addresses are in the new “Bech32” format and look completely different from the previously known addresses. They are slightly longer than normal addresses and contain only lowercase letters.