BSV Addresses & WIFs
Satoshis Are Property
When a transaction is added to the ledger, it acts as a timestamped record of a change of ownership with satoshis (and whatever else is included in the transaction) being the property exchanged. Unlike account-based systems like a bank account where money is added and subtracted to and from the account with each transaction, satoshis aren’t actually ‘sent’ and ‘received' in UTXOs. In much the same way the ownership of gold is transferred without physically moving the gold, the ownership change of satoshis is tagged in UTXOs, and the event itself recorded in transactions. However, it’s important to note that BSV is not digital gold.
Since the BSV ledger is public, the ownership history of all 2,100,000,000,000,000 satoshis can be traced back to their issuance in 2009 by following the chain of digital signatures that link each UTXO and transaction in their history. This means Bitcoin doesn’t have accounts, so identity can be pseudonymously tied to each UTXO allowing macro-level activity to be visible while simultaneously providing individual privacy. It also means there’s a lot more flexibility in how transactions are conducted than account-based systems because a transaction doesn’t need to be submitted by an account holder; it can be submitted by anyone. However, identity is still a fundamental part of communication and UTXOs are still traceable and identity is still attributable when required.
All electronic communications are based on two concepts: using some kind of shared secret or signal so parties know they're talking to the correct people, and attributing identity to documents or messages so parties can attest to their ownership. The two most common methods used to make these two concepts a reality are the Diffie-Hellman key exchange algorithm and digital signatures.
Diffie-Hellman Key Exchange and the Discrete Logarithm Problem (DLP)
Much of the modern world is based on the concept of using a secure secret as a 'seed' value to encrypt communications: symmetric end-to-end (E2E) encryption. There are two problems with this approach:
If everything is encrypted, how can attackers be stopped if they gain access to a system -- since system administrators can't tell good network traffic from bad because everything is encrypted.
How do the communicating parties share the secret seed securely.
We explore how BSV addresses the first problem without using encryption in Chapter 7, but the answer to the second problem was found before the internet began, called the Diffie-Hellman key exchange, and it's based on the idea of using asymmetric, public-private, key-pairs to generate a symmetric shared secret, securely.
Published in 1976 by Ralph Merkle, and named after Whitfield Diffie and Martin Hellman, the Diffie-Hellman key exchange method is the earliest publicly known protocol for exchanging asymmetric keypairs. To this day, Diffie-Hellman is used extensively in everything involving end-to-end encryption, and even in the exchange of physical keys via written notes in some instances.
Essentially, the Diffie-Hellman key exchange algorithm works by taking advantage of the unique mathematical properties of the modulo operation, or in other words, the logarithm space of a given power ‘'. The modulo operation '%' yields the remainder after division: e.g. . However, another way of looking at modulo is that it limits results to a certain space. For example, mod or mod are commonly used in computer science to constrain results to 32- or 64-bit integers because those are the largest integers computers can currently handle natively: uint32 and uint64. This means any number, or key, mod n will remain within the space of 0 to n.
First, two communicating parties agree on two numbers: a generator point ‘', and a certain ‘order’ or modulo space '’ which must be a large prime number. Next, each party picks a random number (the larger, the better) which act as their private keys: and . They then use their private keys and the generator point to calculate their public keys: and . Following that, they exchange their public keys in clear text over a public medium, and they can do so securely because so long as is sufficiently large, it's computationally infeasible to find or from or even when is known -- this is called the Discrete Logarithm Problem (DLP). Once the two parties have exchanged their public keys, all they need to do is exponentiate the other party's public key by their private key, and both parties end up with the same shared secret value '': .
For example, say Alice generates a private key ‘' (currently these kinds of keys are 2,000 to 4,000 bits long for security), and Bob generates a private key '’. Knowing and , Alice can calculate her public key as , and Bob his public key as , and, given a sufficiently large (again 2,000 to 4,000 bits) it's impossible for anyone to figure out what or are without brute-force checking all the possibilities .
From there, Alice and Bob can exchange their public keys knowing it won’t expose their private keys, and then they can use the properties of exponentiation to derive the same secret value:
Digital Signature Algorithm
There's one big problem with the Diffie-Hellman key exchange algorithm: a nefarious actor could intercept the public keys during the exchange, posing as either Alice or Bob, and pass their own public key back. This is called a "man-in-the-middle" attack. Digital signatures are a solution to man-in-the-middle attacks.
A digital signature is a lot like a physical signature; it acts as to associate an individual identity to a document. The advantage digital signatures have over physical signatures is they're much easier to verify. Using a digital signature with at least one of the public key exchange messages in Diffie-Hellman can ensure the key is coming from who it's supposed to be coming from. The most popular digital signature algorithm -- used as the US government standard -- is the aptly named DSA.
Similar to the Diffie-Hellman known parameters '' and '', DSA uses 3 parameters: '', '', and ''. and are randomly generated big prime numbers, where is a multiple of . Like Diffie-Hellman, is the generator point. First Alice and Bob generate a public-private key-pair and , respectively. Similar to Diffie-Hellman, these private keys are randomly generated numbers less than , and their corresponding public keys are generator point to the power of the respective private key modulus .
The two processes of signing a message '', and verifying the signature, then become:
Computing the signature:
Generate a random number ''
Verifying the signature:
Elliptic Curve Diffie-Hellman (ECDH) and the Elliptic Curve Digital Signature Algorithm (ECDSA)
ECDH and ECDSA use pretty much the same process as standard Diffie-Hellman and DSA; again, the major difference being multiplication is used instead of exponentiation. For example, say Alice and Bob have decided to upgrade their system from standard Diffie-Hellman and DSA using a 3,072 bit key-size to ECDH and ECDSA, and they want to maintain the same level of security they currently enjoy:
Standard Diffie-Hellman:
ECDHA:
Standard DSA signature computation for a hash of a message '' using private-public key-pair :
= random integer between 0 and 23072
Generate a random, 1-time use, key ''
ECDSA signature computation for a hash of a message '' using private-public key-pair :
= random integer between 0 and
Generate a random, 1-time use, key ''
Standard DSA signature verification:
ECDSA signature verification:
To take a deeper dive into the math behind elliptic curves in Bitcoin, check out our Bitcoin Primitives: Digital Signatures course.
Although BSV's UTXO model takes a different approach than full end-to-end encryption of all communications, it's still fundamentally based on the two ideas of a shared secret and digital signatures.
What is a BSV Address?
A BSV address is the RIPEMD-160 hash of the SHA-256 hash of the compressed x-coordinate of the public key of a public-private ECDSA key-pair prepended with a version byte and encoded in Base58Check… which sounds a lot more complicated than it actually is.
In P2PKH transactions, BSV addresses are the message digests or the “Public-Key-Hash" the satoshis are “Paid-to”.
What is a WIF?
A WIF (Wallet Import Format) key is similar to a Bitcoin address since they both use the Base58Check encoding; however, instead of using the compressed x-coordinate of the public key, the serialised ‘d' value of a private key is used, and WIFs don't use the HASH-160 of the key value.
Generating a Bitcoin ECDSA Public-Private Keypair in GoLang
To generate a Bitcoin public-private ECDSA keypair in golang using the libsv libraries:
How to Create a BSV Address in Golang
Once a public-private ECDSA keypair has been generated, deriving a BSV address from the public key is easy:
1. Get the compressed x-coordinate of the public key:
2. Hash the compressed x-coordinate of the public key with SHA-256:
3. Hash the result of step 2 with RIPEMD-160:
4. Create a new byte array and prepend with either 1 or ‘M' or 'N’ for mainnet or testnet, respectively:
5. Append the result of step 3 to the result of step 4:
6. Generate and append a checksum to the result of step 5, and then encode the byte array in Base58:
7. Print result to standard out:
Activity – Generate a Bitcoin Address from a compressed public key
Using the hash calculator, generate a Bitcoin address for the following compressed public key:
How to Create a Bitcoin WIF in GoLang:
1. Get the serialised private key 'd':
2. Create an empty byte array, and append with either 1, or 5, depending on whether or not the WIF is for mainnet or testnet, respectively:
3. Append the serialised private key bytes to the byte array from step 2:
4. Append the compression byte at the end to denote a corresponding compressed public key will be used:
5. HASH-256 the byte array from step 4 and save the first 4 bytes:
6. Append the 4 checksum bytes from step 5 to the result from step 4:
7. Encode the result of step 6 in Base58 (since the ‘Check' was added in step 6):
8. Print result to standard out:
Activity – Generate a Bitcoin WIF from a serialised private key
Using the hash calculator, generate a Bitcoin WIF for the following private key 'd' value:
Last updated