Ameba Ownd

アプリで簡単、無料ホームページ作成

Mastering bitcoin 2nd edition pdf free download

2021.12.19 11:17






















Mastering Bitcoin provides the knowledge. You simply supply the passion. The second edition includes: A broad introduction to bitcoin—ideal for non-technical users, investors, and business executives An explanation of the technical foundations of bitcoin and cryptographic currencies for developers, engineers, and software and systems architects Details of the bitcoin decentralized network, peer-to-peer architecture, transaction lifecycle, and security principles New developments such as Segregated Witness, Payment Channels, and Lightning Network Offshoots of the bitcoin and blockchain inventions, including alternative chains, currencies, and applications User stories, analogies, examples, and code snippets illustrating key technical concepts Mastering Bitcoin 2nd Edition Mastering Bitcoin: Programming the Open Blockchain 2nd Edition by Andreas M.


Blockchain is a distributed database that enables permanent, transparent, and secure storage of data. The blockchain technology is the backbone of cryptocurrency and it is gaining popularity with people who work in the finance, government, and arts sectors.


This book is an up-to-date, one-stop guide to this leading technology and its Mastering Blockchain Book Description : Blockchain is a distributed database that enables permanent, transparent, and secure storage of data. Author: Andreas M. Antonopoulos Category: Finances and Money Language: English Page: ISBN: ISBN Description: Mastering Bitcoin is essential reading for everyone interested in learning about bitcoin basics, the technical operation of bitcoin, or if you're building the next great bitcoin killer app or business.


And it's the innovation part which is super fascinating, the blockchain technology behind it, and not just the bitcoin itself. How Bitcoin Works? Download your copy today! Take action today and download this book now at a special price! While some people think that Bitcoin is the main focus, Blockchain is Bitcoin's legacy. Blockchain is the technology behind Bitcoin, the revolutionary 'virtual currency' that's changing the way of people do business.


Blockchain will revolutionize a wide variety of businesses. Blockchain technology is influencing the future of doing Business, therefore instead of fall behind, take advantages now, and learn how to master Blockchain today! Communication will effect, in fact already in motion and clearly visible everywhere: -Person to Person -Business to Business - B2B -Machine to Machine - M2M This book has lots of in depth information that will help you to understand the blockchain technology.


Detailed guide on all Blockchain attributes, and how the technology works, behind bitcoin! This Advanced Guide is an excellent choice to gain: -Better understanding of what Blockchain is, -How it improves data integrity, -How it fundamentally changes the future of doing business, -How it enhances data security.


Bitcoin is a cryptographic currency… Purchase this in-depth summary to learn more. They are like rouge intermediaries with absolute control and hold all the power and can print money on a whim. How much longer can we allow this dysfunctional system of currency exchange to exist? This is the digital age and this new wave of currency will impact the lives of millions and even billions worldwide! Meaning no more scandals from third party intermediaries who can print money out of thin air!


No more centralized banks! If you are wondering how can all this be possible? Than it is strongly recommended you grab your copy now and learn everything you need to know about bitcoin, whether you want to invest or understand the convoluted concepts of cyptocurrency in the most easy to read and detailed step by step guide in plain English! Not enough? Ok, well there's more This book also includes bonus chapters and diagrams!


This book is truly set apart from the rest and is vastly superior. There's an entire section dedicated to blockchain technology as understanding the fundamental technology behind bitcoin is as equally as important itself. Why would you want to run a node? Here are some of the most common reasons: If you are developing bitcoin software and need to rely on a bitcoin node for programmable API access to the network and blockchain.


Typically, bitcoin software companies run several nodes. If you want to support bitcoin. Running a node makes the network more robust and able to serve more wallets, more users, and more transactions.


If you do not want to rely on any third party to process or validate your transactions. If the file does not exist, create it with owner-readable-only file permissions. Additionally, it is recommended that you set up the alerting mechanism. In the next section we will examine the various configuration options and set up a configuration file. Configuring the Bitcoin Core Node Edit the configuration file in your preferred editor and set the parameters, replacing the password with a strong password as recommended by bitcoind.


Do not use the password shown in the book. To see a listing of these options, run bitcoind --help: bitcoind --help Bitcoin Core Daemon version v0. By default this is the. Make sure this filesystem has several gigabytes of free space. This means a complete copy of the blockchain that allows you to programmatically retrieve any transaction by ID.


Reducing this from the default will reduce your bandwidth consumption. Use if you have a data cap or pay by the gigabyte. Use it to reduce memory use of the node. Use on memory-constrained nodes. Below this value, the transaction is treated as zero fee. Use this on memory-constrained nodes to reduce the size of the in-memory transaction pool.


Example shows how you might combine the preceding options, with a fully indexed node, running as an API backend for a bitcoin application. To run Bitcoin Core in the background as a process, start it with the daemon option, as bitcoind - daemon.


Once you are happy with the configuration options you have selected, you should add bitcoin to the startup scripts in your operating system, so that it runs continuously and restarts when the operating system restarts. The command line allows us to experiment interactively with the capabilities that are also available programmatically via the API. To get additional help, a detailed description, and information on the parameters, add the command name after help.


Arguments: 1. These examples demonstrate how you might call the command. But for now, this command should return the same result on your system, demonstrating that your Bitcoin Core node is running, is accepting commands, and has information about block to return to you.


In the next sections we will demonstrate some very useful RPC commands and their expected output. Among this data we see the version numbers for the bitcoin software client and bitcoin protocol We see the current block height, showing us how many blocks are known to this client We also see various statistics about the bitcoin network and the settings related to this client. You can check its progress using getinfo to see the number of known blocks. Her transaction was recorded on the blockchain with transaction ID txid b6ffaeaf2ce4da4caa5a5fbd8acc2f2.


Absence of a transaction hash in the blockchain does not mean the transaction was not processed. After confirmation, the txid is immutable and authoritative. The command getrawtransaction returns a serialized transaction in hexadecimal notation.


To decode that, we use the decoderawtransaction command, passing the hex data as a parameter. In this case we see that the transaction that credited our new address with 50 millibits used one input and generated two outputs. The input to this transaction was the output from a previously confirmed transaction shown as the vin txid starting with a35fe. The two outputs correspond to the 50 millibit credit and an output with change back to the sender. We can further explore the blockchain by examining the previous transaction referenced by its txid in this transaction using the same commands e.


Jumping from transaction to transaction we can follow a chain of transactions back as the coins are transmitted from owner address to owner address. However, blocks can be referenced either by the block height or by the block hash. The height entry tells us this is the th block in the blockchain. But the whole point of an application programming interface is to access functions programmatically.


In this section we will demonstrate accessing Bitcoin Core from another program. JSON stands for JavaScript Object Notation and it is a very convenient way to present data that both humans and programs can easily read.


RPC stands for Remote Procedure Call, which means that we are calling procedures functions that are remote on the Bitcoin Core node via a network protocol. We will use the python-bitcoinlib library to simplify API access.


The Python script in Example makes a simple getinfo call and prints the block parameter from the data returned by Bitcoin Core. For each output, we show the recipient address and value.


Retrieving a transaction and iterating its outputs from bitcoin. The next example, however, requires several hundred RPC calls and more clearly demonstrates the use of a programmatic interface. In Example , we first retrieve block , then retrieve each of the transactions within by reference to each transaction ID. Retrieving a block and adding all the transaction outputs from bitcoin. Compare that to the amount reported by a block explorer site by searching for the block hash or height.


Some block explorers report the total value excluding the reward and excluding the fees. See if you can spot the difference. Alternative Clients, Libraries, and Toolkits There are many alternative clients, libraries, toolkits, and even full-node implementations in the bitcoin ecosystem. These are implemented in a variety of programming languages, offering programmers native interfaces in their preferred language.


The following sections list some of the best libraries, clients, and toolkits, organized by programming languages.


Chapter 4. Keys, Addresses You may have heard that bitcoin is based on cryptography, which is a branch of mathematics used extensively in computer security. Cryptography can also be used to prove knowledge of a secret without revealing that secret digital signature , or prove the authenticity of data digital fingerprint. These types of cryptographic proofs are the mathematical tools critical to bitcoin and used extensively in bitcoin applications.


Ironically, encryption is not an important part of bitcoin, as its communications and transaction data are not encrypted and do not need to be encrypted to protect the funds. In this chapter we will introduce some of the cryptography used in bitcoin to control ownership of funds, in the form of keys, addresses, and wallets. Introduction Ownership of bitcoin is established through digital keys, bitcoin addresses, and digital signatures. The digital keys are not actually stored in the network, but are instead created and stored by users in a file, or simple database, called a wallet.


Keys enable many of the interesting properties of bitcoin, including decentralized trust and control, ownership attestation, and the cryptographic-proof security model. Most bitcoin transactions requires a valid digital signature to be included in the blockchain, which can only be generated with a secret key; therefore, anyone with a copy of that key has control of the bitcoin.


The digital signature used to spend funds is also referred to as a witness, a term used in cryptography. The witness data in a bitcoin transaction testifies to the true ownership of the funds being spent. Keys come in pairs consisting of a private secret key and a public key. Think of the public key as similar to a bank account number and the private key as similar to the secret PIN, or signature on a check, that provides control over the account.


These digital keys are very rarely seen by the users of bitcoin. For the most part, they are stored inside the wallet file and managed by the bitcoin wallet software. In most cases, a bitcoin address is generated from and corresponds to a public key. However, not all bitcoin addresses represent public keys; they can also represent other beneficiaries such as scripts, as we will see later in this chapter.


The bitcoin address is the only representation of the keys that users will routinely see, because this is the part they need to share with the world. First, we will introduce cryptography and explain the mathematics used in bitcoin. Next, we will look at how keys are generated, stored, and managed. Finally, we will look at advanced use of keys and addresses: vanity, multisignature, and script addresses and paper wallets.


Public Key Cryptography and Cryptocurrency Public key cryptography was invented in the s and is a mathematical foundation for computer and information security.


Since the invention of public key cryptography, several suitable mathematical functions, such as prime number exponentiation and elliptic curve multiplication, have been discovered. These mathematical functions are practically irreversible, meaning that they are easy to calculate in one direction and infeasible to calculate in the opposite direction.


Based on these mathematical functions, cryptography enables the creation of digital secrets and unforgeable digital signatures. Bitcoin uses elliptic curve multiplication as the basis for its cryptography. In bitcoin, we use public key cryptography to create a key pair that controls access to bitcoin. The key pair consists of a private key and—derived from it—a unique public key. The public key is used to receive funds, and the private key is used to sign transactions to spend the funds.


There is a mathematical relationship between the public and the private key that allows the private key to be used to generate signatures on messages. This signature can be validated against the public key without revealing the private key.


When spending bitcoin, the current bitcoin owner presents her public key and a signature different each time, but created from the same private key in a transaction to spend those bitcoin. Through the presentation of the public key and signature, everyone in the bitcoin network can verify and accept the transaction as valid, confirming that the person transferring the bitcoin owned them at the time of the transfer. TIP In most wallet implementations, the private and public keys are stored together as a key pair for convenience.


However, the public key can be calculated from the private key, so storing only the private key is also possible. Private and Public Keys A bitcoin wallet contains a collection of key pairs, each consisting of a private key and a public key. The private key k is a number, usually picked at random.


From the private key, we use elliptic curve multiplication, a one-way cryptographic function, to generate a public key K. From the public key K , we use a one-way cryptographic hash function to generate a bitcoin address A.


In this section, we will start with generating the private key, look at the elliptic curve math that is used to turn that into a public key, and finally, generate a bitcoin address from the public key. The relationship between private key, public key, and bitcoin address is shown in Figure Why is asymmetric cryptography used in bitcoin? Rather, the useful property of asymmetric cryptography is the ability to generate digital signatures.


A private key can be applied to the digital fingerprint of a transaction to produce a numerical signature. This signature can only be produced by someone with knowledge of the private key. However, anyone with access to the public key and the transaction fingerprint can use them to verify the signature.


This useful property of asymmetric cryptography makes it possible for anyone to verify every signature on every transaction, while ensuring that only the owners of private keys can produce valid signatures. Private Keys A private key is simply a number, picked at random. Ownership and control over the private key is the root of user control over all funds associated with the corresponding bitcoin address.


The private key is used to create signatures that are required to spend bitcoin by proving ownership of funds used in a transaction. The private key must remain secret at all times, because revealing it to third parties is equivalent to giving them control over the bitcoin secured by that key. TIP The bitcoin private key is just a number. You can pick your private keys randomly using just a coin, pencil, and paper: toss a coin times and you have the binary digits of a random private key you can use in a bitcoin wallet.


The public key can then be generated from the private key. Generating a private key from a random number The first and most important step in generating keys is to find a secure source of entropy, or randomness. Usually, the OS random number generator is initialized by a human source of randomness, which is why you may be asked to wiggle your mouse around for a few seconds.


To create such a key, we randomly pick a bit number and check that it is less than n - 1. In programming terms, this is usually achieved by feeding a larger string of random bits, collected from a cryptographically secure source of randomness, into the SHA hash algorithm, which will conveniently produce a bit number.


If the result is less than n - 1, we have a suitable private key. Otherwise, we simply try again with another random number. Study the documentation of the random number generator library you choose to make sure it is cryptographically secure. It is approximately in decimal. For comparison, the visible universe is estimated to contain atoms.


To generate a new key with the Bitcoin Core client see Chapter 3 , use the getnewaddress command. For security reasons it displays the public key only, not the private key.


To ask bitcoind to expose the private key, use the dumpprivkey command. It is not possible for bitcoind to know the private key from the public key unless they are both stored in the wallet.


TIP The dumpprivkey command does not generate a private key from a public key, as this is impossible. The command simply reveals the private key that is already known to the wallet and which was generated by the getnewaddress command. The owner of the private key can easily create the public key and then share it with the world knowing that no one can reverse the function and calculate the private key from the public key.


This mathematical trick becomes the basis for unforgeable and secure digital signatures that prove ownership of bitcoin funds. Elliptic Curve Cryptography Explained Elliptic curve cryptography is a type of asymmetric or public key cryptography based on the discrete logarithm problem as expressed by addition and multiplication on the points of an elliptic curve.


Figure is an example of an elliptic curve, similar to that used by bitcoin. An elliptic curve Bitcoin uses a specific elliptic curve and set of mathematical constants, as defined in a standard called secpk1, established by the National Institute of Standards and Technology NIST.


Because this curve is defined over a finite field of prime order instead of over the real numbers, it looks like a pattern of dots scattered in two dimensions, which makes it difficult to visualize. However, the math is identical to that of an elliptic curve over real numbers. As an example, Figure shows the same elliptic curve over a much smaller finite field of prime order 17, showing a pattern of dots on a grid.


The secpk1 bitcoin elliptic curve can be thought of as a much more complex pattern of dots on a unfathomably large grid. Geometrically, this third point P3 is calculated by drawing a line between P1 and P2. This line will intersect the elliptic curve in exactly one additional place.


This tangent will intersect the curve in exactly one new point. You can use techniques from calculus to determine the slope of the tangent line. These techniques curiously work, even though we are restricting our interest to points on the curve with two integer coordinates! In some cases i. This shows how the point at infinity plays the role of zero. Now that we have defined addition, we can define multiplication in the standard way that extends addition. Generating a Public Key Starting with a private key in the form of a randomly generated number k, we multiply it by a predetermined point on the curve called the generator point G to produce another point somewhere else on the curve, which is the corresponding public key K.


The generator point is specified as part of the secpk1 standard and is always the same for all keys in bitcoin: where k is the private key, G is the generator point, and K is the resulting public key, a point on the curve.


Because the generator point is always the same for all bitcoin users, a private key k multiplied with G will always result in the same public key K. The relationship between k and K is fixed, but can only be calculated in one direction, from k to K.


TIP A private key can be converted into a public key, but a public key cannot be converted back into a private key because the math only works one way. Our goal is to find the multiple kG of the generator point G, which is the same as adding G to itself, k times in a row. In elliptic curves, adding a point to itself is the equivalent of drawing a tangent line on the point and finding where it intersects the curve again, then reflecting that point on the x-axis. Figure shows the process for deriving G, 2G, 4G, as a geometric operation on the curve.


Elliptic curve cryptography: visualizing the multiplication of a point G by an integer k on an elliptic curve Bitcoin Addresses A bitcoin address is a string of digits and characters that can be shared with anyone who wants to send you money. Because paper checks do not need to specify an account, but rather use an abstract name as the recipient of funds, they are very flexible payment instruments.


Bitcoin transactions use a similar abstraction, the bitcoin address, to make them very flexible. The bitcoin address is derived from the public key through the use of one-way cryptographic hashing.


Cryptographic hash functions are used extensively in bitcoin: in bitcoin addresses, in script addresses, and in the mining Proof-of-Work algorithm. TIP A bitcoin address is not the same as a public key. Bitcoin addresses are derived from a public key using a one-way function. Base58Check is also used in many other ways in bitcoin, whenever there is a need for a user to read and correctly transcribe a number, such as a bitcoin address, a private key, an encrypted key, or a script hash.


In the next section we will examine the mechanics of Base58Check encoding and decoding and the resulting representations. Figure illustrates the conversion of a public key into a bitcoin address. Public key to bitcoin address: conversion of a public key into a bitcoin address Base58 and Base58Check Encoding In order to represent long numbers in a compact way, using fewer symbols, many computer systems use mixed-alphanumeric representations with a base or radix higher than A number represented in hexadecimal format is shorter than the equivalent decimal representation.


Base64 is most commonly used to add binary attachments to email. Base58 is a text-based binary-encoding format developed for use in bitcoin and used in many other cryptocurrencies.


It offers a balance between compact representation, readability, and error detection and prevention. Base58 is a subset of Base64, using upper- and lowercase letters and numbers, but omitting some characters that are frequently mistaken for one another and can appear identical when displayed in certain fonts.


Or, more simply, it is a set of lowercase and capital letters and numbers without the four 0, O, l, I just mentioned.


Example shows the full Base58 alphabet. The checksum is an additional four bytes added to the end of the data that is being encoded. The checksum is derived from the hash of the encoded data and can therefore be used to detect and prevent transcription and typing errors. When presented with Base58Check code, the decoding software will calculate the checksum of the data and compare it to the checksum included in the code.


If the two do not match, an error has been introduced and the Base58Check data is invalid. This prevents a mistyped bitcoin address from being accepted by the wallet software as a valid destination, an error that would otherwise result in loss of funds.


For example, in the case of a bitcoin address the prefix is zero 0x00 in hex , whereas the prefix used when encoding a private key is 0x80 in hex. A list of common version prefixes is shown in Table These four bytes serve as the error-checking code, or checksum. The checksum is concatenated appended to the end.


The result is composed of three items: a prefix, the data, and a checksum. This result is encoded using the Base58 alphabet described previously.


Figure illustrates the Base58Check encoding process. Base58Check encoding: a Base58, versioned, and checksummed format for unambiguously encoding bitcoin data In bitcoin, most of the data presented to the user is Base58Check-encoded to make it compact, easy to read, and easy to detect errors.


The version prefix in Base58Check encoding is used to create easily distinguishable formats, which when encoded in Base58 contain specific characters at the beginning of the Base58Check-encoded payload. These characters make it easy for humans to identify the type of data that is encoded and how to use it.


This is what differentiates, for example, a Base58Check-encoded bitcoin address that starts with a 1 from a Base58Check-encoded private key WIF that starts with a 5. Some example version prefixes and the resulting Base58 characters are shown in Table Table Compiling and running the addr code Compile the addr.


These representations all encode the same number, even though they look different. These formats are primarily used to make it easy for people to read and transcribe keys without introducing errors. Private key formats The private key can be represented in a number of different formats, all of which correspond to the same bit number.


Table shows three common formats used to represent private keys. Different formats are used in different circumstances. Hexadecimal and raw binary formats are used internally in software and rarely shown to users.


They look different, but any one format can easily be converted to any other format. You can use Bitcoin Explorer to decode the Base58Check format on the command line.


Public key formats Public keys are also presented in different ways, usually as either compressed or uncompressed public keys. As we saw previously, the public key is a point on the elliptic curve consisting of a pair of coordinates x,y.


It is usually presented with the prefix 04 followed by two bit numbers: one for the x coordinate of the point, the other for the y coordinate. The prefix 04 is used to distinguish uncompressed public keys from compressed public keys that begin with a 02 or a That allows us to store only the x coordinate of the public key point, omitting the y coordinate and reducing the size of the key and the space required to store it by bits.


Whereas uncompressed public keys have a prefix of 04, compressed public keys start with either a 02 or a 03 prefix. Visually, this means that the resulting y coordinate can be above or below the x-axis. As you can see from the graph of the elliptic curve in Figure , the curve is symmetric, meaning it is reflected like a mirror by the x-axis.


So, while we can omit the y coordinate we have to store the sign of y positive or negative ; or in other words, we have to remember if it was above or below the x-axis because each of those options represents a different point and a different public key. Therefore, to distinguish between the two possible values of y, we store a compressed public key with the prefix 02 if the y is even, and 03 if it is odd, allowing the software to correctly deduce the y coordinate from the x coordinate and uncompress the public key to the full coordinates of the point.


Public key compression is illustrated in Figure