|
1 | 1 | =head1 NAME |
2 | 2 |
|
3 | | -Bitcoin::Crypto::Manual - Module overview |
| 3 | +Bitcoin::Crypto::Manual - Main reference to Bitcoin::Crypto |
4 | 4 |
|
5 | 5 | =head1 DESCRIPTION |
6 | 6 |
|
7 | | -This module allows you to perform low-level tasks for Bitcoin such as: |
| 7 | +Bitcoin::Crypto is a mature cryptographic Perl module for Bitcoin management. |
| 8 | +It focuses on delivering unopinionated tools which make it possible to manage |
| 9 | +Bitcoin with Perl code. The following list of topics is an overview of module's |
| 10 | +capabilities: |
8 | 11 |
|
9 | 12 | =over |
10 | 13 |
|
11 | | -=item * creating extended keys and utilizing bip32 key derivation |
| 14 | +=item * keypair management, key derivation, address generation |
12 | 15 |
|
13 | | -=item * creating private key / public key pairs |
| 16 | +=item * block and transaction building and management |
14 | 17 |
|
15 | | -=item * address generation (in legacy, compatibility and segwit formats) |
| 18 | +=item * signing and verifying transactions |
16 | 19 |
|
17 | | -=item * importing / exporting using popular mediums (WIF, mnemonic, hex) |
| 20 | +=item * script building and execution |
18 | 21 |
|
19 | | -=item * building, serializing and running transaction scripts |
20 | | - |
21 | | -=item * serializing, signing and verifying transactions |
22 | | - |
23 | | -=item * serializing bitcoin blocks |
| 22 | +=item * Bitcoin-related formats: PSBT, bech32, base58, mnemonics |
24 | 23 |
|
25 | 24 | =back |
26 | 25 |
|
27 | | -This module won't help you with: |
28 | | - |
29 | | -=over |
30 | | - |
31 | | -=item * using any Bitcoin CLI tools / clients |
32 | | - |
33 | | -=item * connecting to Bitcoin network |
34 | | - |
35 | | -=back |
| 26 | +=head1 THE BASICS |
| 27 | + |
| 28 | +=head2 Bitcoin protocol overview |
| 29 | + |
| 30 | +Bitcoin is a decentralized ledger of transactions. Transactions come in a |
| 31 | +sequence, one after another. This sequence is split into chunks, called blocks. |
| 32 | +Blocks are generated in a process called mining, which tries to randomly find a |
| 33 | +block with a certain hashed value. That value is adjusted periodically, so that |
| 34 | +each block is mined every 10 minutes (on average). The entire point of mining |
| 35 | +is to prove that a significant amount of time and energy was spent finding a |
| 36 | +block. This is called I<Proof of Work> (PoW), and is a way to gain trust in a |
| 37 | +trustless, decentralized system. Miner which found a block has the right to |
| 38 | +inject a limited number of new coins into the system, which is how all coins in |
| 39 | +existence were created. |
| 40 | + |
| 41 | +Transaction is the single most important structure in Bitcoin. It defines where |
| 42 | +the coins came from (inputs) and where they will end up (outputs). Transaction |
| 43 | +can have multiple inputs and multiple outputs. Each input must point to an |
| 44 | +output of a previous transaction, and spend it entirely. Once the output is |
| 45 | +used in a transaction, it is no longer considered an UTXO (unspent transaction |
| 46 | +output), and can't be spent again. Since UTXOs must be spent entirely at once, |
| 47 | +any coins exceeding the payment amount must be sent to outputs controlled by |
| 48 | +the sender. |
| 49 | + |
| 50 | +Bitcoin script is a language for defining spend conditions for outputs. Each |
| 51 | +transaction output has a I<locking script> which must yield success when the |
| 52 | +transaction is verified. Transaction inputs define initial conditions for |
| 53 | +execution of locking script, in form of I<signature script> or I<witness>. Vast |
| 54 | +majority of output scripts contain a public key and signature checking against |
| 55 | +the serialized form of the transaction. |
| 56 | + |
| 57 | +To prove ownership of coins, Bitcoin uses assymetric cryptography over an |
| 58 | +C<secp256k1> Elliptic Curve. Most bitcoin locking scripts are standard type |
| 59 | +scripts, which can be recognized as I<addresses>. Each private/public keypair |
| 60 | +corresponds to a single address. An example of a standard script is C<P2TR> |
| 61 | +("pay to taproot"), and its locking script can be encoded as a I<bech32> |
| 62 | +address starting with C<bc1p>. That address contains the public key, and |
| 63 | +spending coins sent to it requires a signature from the corresponding private |
| 64 | +key. Once a transaction creates an UTXO to an address corresponding to a |
| 65 | +private/public keypair, the coins are considered to be owned by the person who |
| 66 | +controls th private key. |
| 67 | + |
| 68 | +=head2 Whitepaper and Bitcoin Improvement Proposals |
| 69 | + |
| 70 | +Original Bitcoin was proposed and implemented by Satoshi Nakamoto. The original |
| 71 | +document which defines how Bitcoin works (without much detail) is called the |
| 72 | +Bitcoin Whitepaper. Since Bitcoin inception it has been modified heavily, and |
| 73 | +most influential changes were introduced as Bitcoin Improvement Proposals |
| 74 | +(I<BIPs>). |
| 75 | + |
| 76 | +Each BIP has its unique number and defines one change or new feature. It is |
| 77 | +very common to use some BIP numbers to refer to that change or feature. All |
| 78 | +BIPs can be viewed in their GitHub repository: |
| 79 | +L<https://github.com/bitcoin/bips>. |
| 80 | + |
| 81 | +=head2 Storing and accessing secrets |
| 82 | + |
| 83 | +The primary method of storing private keys for Bitcoin is mnemonic phrases, |
| 84 | +which are sets of 12 to 24 human-readable words. Mnemonics can be imported and |
| 85 | +turned into an extended key, which can be used to derive unlimited number of |
| 86 | +addresses. Mnemonics can be stored securely away from devices connected to the |
| 87 | +Internet, or without a computer at all, for example written of a piece of paper |
| 88 | +- this is called I<cold storage>. Secrets stored on a computer connected to an |
| 89 | +Internet are called I<hot storage>, and have greater than zero chance to be |
| 90 | +hacked. |
| 91 | + |
| 92 | +Key derivation uses standardized paths, referred to as I<BIP44>. This |
| 93 | +standardization allows different wallet software to access the coins stored on |
| 94 | +a mnemonic. Keys are derived using Hierarchical-Deterministic algorithm, and |
| 95 | +keys are generating in sequence. This ensures no coins will be lost within one |
| 96 | +mnemonic. |
36 | 97 |
|
37 | 98 | =head1 WHERE TO START? |
38 | 99 |
|
39 | | -Documentation and examples in this module assume you're already familiar with |
40 | | -the basics of Bitcoin protocol and asymmetric cryptography. If that's not the |
41 | | -case, start with reading about those topics. |
42 | | - |
43 | | -If you like to learn by example, dive right into the examples directory. |
44 | | - |
45 | 100 | There are many goals which you may want to achieve with this module. Common |
46 | 101 | topics include: |
47 | 102 |
|
@@ -358,8 +413,6 @@ I will gladly accept help working on these: |
358 | 413 |
|
359 | 414 | =over |
360 | 415 |
|
361 | | -=item * All listed in L<Bitcoin::Crypto::Manual::Transactions/Current known problems with transactions> |
362 | | - |
363 | 416 | =item * All issues with C<help wanted> tag on GitHub |
364 | 417 |
|
365 | 418 | =item * Better error checking (edge cases etc.) |
|
0 commit comments