- Notifications
You must be signed in to change notification settings - Fork309
Update private_key.md#81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
youngminpark2559 wants to merge72 commits intoProgrammingBlockchain:masterChoose a base branch fromyoungminpark2559:master
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
72 commits Select commitHold shift + click to select a range
d4c9968
Update private_key.md
youngminpark25592845c76
Update comment
youngminpark2559fa5e560
Is adding "key" along with address more precise?
youngminpark25596c1474e
Update private_key.md
youngminpark25590833f44
Add contents about CombineSignatures()
youngminpark25592360117
Merge pull request #1 from youngmtool/youngmtool-patch-1
youngminpark2559474bc99
Merge branch 'master' into master
nopara737b44a07
Update bitcoin_address.md
youngminpark2559967fda6
Edit code block separation
youngminpark2559646bda1
Fix grammatical typos and add section separations
youngminpark25593123abb
Fix multi-signing to multi-sig
youngminpark255979d86de
Fix an indentation
youngminpark2559853b29e
Fix typo
youngminpark255923ece61
Put a punctuation
youngminpark255910c85ab
Add additional explanation
youngminpark255943d0674
Update bitcoin_address.md
youngminpark2559089cb6e
Update bitcoin_address.md
youngminpark2559515eecc
Update bitcoin_address.md
youngminpark255948dbef8
Add explanatory word
youngminpark25592cc6024
Update transaction.md
youngminpark2559e049232
Update private_key.md
youngminpark25599837130
Update spend_your_coin.md
youngminpark2559ec56222
Update spend_your_coin.md
youngminpark25591c485af
Update spend_your_coin.md
youngminpark25591017139
Please anyone check if it is how
youngminpark2559b94f168
Update spend_your_coin.md
youngminpark25593e30802
Question.
youngminpark25592323592
Update key_generation.md
youngminpark255982b4288
Update key_generation.md
youngminpark25595d4452e
Back some part(new Key(), privateKey) back to previous one in bitcoin…
youngminpark25590adb917
Update bitcoin_address.md
youngminpark255912c6cc9
Update key_generation.md
youngminpark2559e69ecb8
Update key_generation.md
youngminpark2559b13b5d7
Add explanation of a key object
youngminpark2559321004f
Update bitcoin_address.md
youngminpark25592ff67fb
Update bitcoin_address.md
youngminpark2559e1df4c4
Update key_generation.md
youngminpark2559b40d3f1
Update mnemonic-code-for-hd-keys-bip39
youngminpark25596bdbc55
Update p2pk[h]_pay_to_public_key_[hash].md
youngminpark25594594789
Update arbitrary.md
youngminpark2559a5c85bc
Update arbitrary.md
youngminpark2559f194da2
Update arbitrary.md
youngminpark2559327348c
Merge branch 'master' into master
youngminpark2559abacd15
Update private_key.md
youngminpark25599a1ab2a
Update private_key.md
youngminpark2559eccec6e
Update bitcoin_address.md
youngminpark25597b85551
Update README.md
youngminpark2559980b98d
Update bitcoin_address.md
youngminpark25590fe52c9
Update bitcoin_address.md
youngminpark255953da20f
Update arbitrary.md
youngminpark2559ef6aa73
Update arbitrary.md
youngminpark255942ce6ed
Update bitcoin_address.md
youngminpark2559284c111
Update bitcoin_address.md
youngminpark25596fb599a
Update private_key.md
youngminpark2559e624bb2
Update transaction.md
youngminpark25591a79cb6
Update blockchain.md
youngminpark25593caa60d
Update blockchain.md
youngminpark2559e3b4f8d
Update blockchain.md
youngminpark25592a6dcd7
Update blockchain.md
youngminpark2559d3c9b31
Update blockchain.md
youngminpark2559c83cce3
Update blockchain.md
youngminpark255921726d5
Update the_blockchain_is_more_than_just_bitcoin.md
youngminpark2559c8abaee
Update proof_of_ownership_as_an_authentication_method.md
youngminpark2559cb2bd3b
Update proof_of_ownership_as_an_authentication_method.md
youngminpark2559a4c9f4a
Update spend_your_coin.md
youngminpark2559220b3de
Update colored_coins.md
youngminpark25599458ef8
Update blockchain.md
youngminpark2559f8bcaa5
Update issuing_an_asset.md
youngminpark2559354703e
Update README.md
youngminpark25598881763
Update bitcoin_address.md
youngminpark2559971b4f8
Update payment_script.md
youngminpark2559869b59f
Update private_key.md
youngminpark2559File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
6 changes: 3 additions & 3 deletionsbitcoin_transfer/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#Part3.Bitcoin transfer {#bitcoin-transfer} | ||
In Bitcoin, everything is designed to make sure that the transactions go through. In this chapter, we are going to introduce the basic concepts of Bitcoin by guiding you through a creation of simple bitcoin transaction "by hand". | ||
Later, we are going to show you a higher level framework for building transactions. |
123 changes: 99 additions & 24 deletionsbitcoin_transfer/bitcoin_address.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,133 @@ | ||
# Chapter1. Bitcoin address {#bitcoin-address} | ||
## Section1. Bitcoin address | ||
You know that your **Bitcoin address** is what you share to the world to get paid. | ||
 | ||
You probably know that your wallet software uses a **private key** to spend the money you receivedfor sending the meney to the Bitcoin address. | ||
 | ||
The keys, a private key and a public key,are not stored on the network and they can be generated without an access to the Internet. | ||
This is how you generate a private key with NBitcoin: | ||
```cs | ||
//Generate a random private key. | ||
Key privateKey = new Key(); | ||
Console.WriteLine($"privateKey: {privateKey.ToString(Network.Main)}"); | ||
//Output: | ||
//L3gyRGQ8Da1mMnDFkM9sFYbTV7P8hN8vHzmkALsfkyK7Wjfby5ZB | ||
``` | ||
The ouput from above code is showing one generated private key. | ||
And we use a one-way cryptographic function on the private key to generate a **public key**. | ||
 | ||
```cs | ||
PubKey publicKey = privateKey.PubKey; | ||
Console.WriteLine(publicKey); | ||
//Output: | ||
//0251036303164f6c458e9f7abecb4e55e5ce9ec2b2f1d06d633c9653a07976560c | ||
``` | ||
## Section2. Dive into more details of "new Key()", a private key, a public key. | ||
You're probably doubtful when you see a "Key privateKey = new Key()" from above code, with saying "Should the variable name for the privateKey be named by keyObject rather than the privateKey? | ||
Yes, it is a key object. If you print a privateKey variable by: | ||
```cs | ||
Console.WriteLine(privateKey); | ||
``` | ||
, you'll see the output like this: | ||
```cs | ||
NBitcoin.Key | ||
``` | ||
Moreover, you can do lots of tasks by this key object. Try to examine what you can do by this key object by using IntelliSense like this: | ||
```cs | ||
Console.WriteLine(privateKey.); | ||
``` | ||
You're going to be more sure it's a key object once you examine a Key class because a Key class looks like an ordinary class including lots of its members. | ||
It's true that an object which is created by "new Key()" is a key object. | ||
**However, in the NBitcoin, we often use an object which is created by "new Key()" as a private key.** | ||
When you instantiate a key object, under the hood, in the case of the NBitcoin, you simultaneously invoke a secure PRNG(Pseudo-Random Number Generator) by default to generate a random key data and store it into a key object. | ||
For more details, reference a "Is it random enough?" chapter of "Key generation and encryption" part. | ||
As mentioned above, a key object generated in this way contains a randomly generated key data in the object. And this object is often used in generating other types of key such as a public key, BitcoinSecret(nothing but a private key represented in Base58Check binary-to-text encoding scheme allowing you to use the private key in the UI layer, and Bitcoin secret is exactly identical concept with a WIF except for its differently called name.), a ScriptPubKey and so on. | ||
## Section3. Bitcoin network and Bitcoin address | ||
There are two Bitcoin **networks**: | ||
* **TestNet** is a Bitcoin network for development purposes. Bitcoins on this network worth nothing. | ||
* **MainNet** is the Bitcoin network everybody uses. | ||
> **Note:** You can acquire testnet coins quickly by using **faucets**. Just google "get testnet bitcoins". | ||
You can easily get yourBitcoin address from your"public key" and the"network identifier" on which this address should be used. | ||
 | ||
```cs | ||
Console.WriteLine(publicKey.GetAddress(Network.Main)); | ||
//Output: | ||
//1PUYsjwfNmX64wS368ZR5FMouTtUmvtmTY | ||
Console.WriteLine(publicKey.GetAddress(Network.TestNet)); | ||
//Output: | ||
//n3zWAo2eBnxLr3ueohXnuAa8mTVBhxmPhq | ||
``` | ||
Note that a Bitcoin address for mainnet starts with "1", and a Bitcoin address for testnet starts with "m" or "n". | ||
**To be precise, a Bitcoin address is made up of a "version byte" which is different on both networks(mainnet, testnet). But this version byte identifies the network type. And a Bitcoin address is also made of your "public key’s hash bytes". Both of these bytes are concatenated and then encoded into a Base58Check encoding scheme which has an additional 4 bytes checksum data, compared to a Base58:** | ||
In other words, it means that a generated Bitcoin address isalways in Base58Check encoding scheme.(If this is wrong, please edit it.) | ||
 | ||
The above illustration shows a standard way of generating a Bitcoin address by processing entire steps(Public key -> Public key hash + Network => Bitcoin address), with not using a sugar syntax for generating a Bitcoin address(Public key + Network => Bitcoin address). | ||
```cs | ||
var publicKeyHash = publicKey.Hash; | ||
Console.WriteLine(publicKeyHash); | ||
//Output: | ||
//f6889b21b5540353a29ed18c45ea0031280c42cf | ||
//Get a Bitcoin address for a mainnet by publicKeyHash and network identifier. | ||
var bitcoinAddressForMainNet = publicKeyHash.GetAddress(Network.Main); | ||
var bitcoinAddressForTestNet = publicKeyHash.GetAddress(Network.TestNet); | ||
Console.WriteLine(mainNetAddress); | ||
//Output: | ||
//1PUYsjwfNmX64wS368ZR5FMouTtUmvtmTY | ||
Console.WriteLine(testNetAddress); | ||
//Output: | ||
//n3zWAo2eBnxLr3ueohXnuAa8mTVBhxmPhq | ||
``` | ||
> **Fact:**Internally, a **public key hash** is generated by using a SHA256cryptographichashfunctionon the public key, then a RIPEMD160cryptographichashfunctionon the result, using Big Endian notation. The function could look like this: RIPEMD160(SHA256(publickey)) | ||
## Section4. Encoding schemes | ||
There is a one binary-to-text encoding scheme which is called Base64. | ||
Base64 represents binary data in an ASCII string format with 64 characters composed of A-Z, a-z, 0-9, and +(plus) ,/(slash). | ||
A Base58 is a modification of the Base64 which was first suggested by Satoshi Nakamoto for Bitcoin system implementation. | ||
The Base58 uses 58 characters by eleminating 6 characters from the Base64 such as 0(zero), O(uppercase o), I(uppercase i), l(lowercase L), +(plus), and /(slash) to avoid a mistake by an ambiguity of characters. | ||
A Base58Check encoding scheme, a modification of the Base58, has some neat features like a checksum to prevent typos being occured aside from a lack of ambiguous characters such as '0' and 'O' from the Base58. | ||
The Base58Check encoding scheme also provides a consistent way to determine the network type from a given address, which means that this feature prevents a wallet from sending MainNet coins to a TestNet address. | ||
```cs | ||
//Get the Bitcoin address for each network type. | ||
var bitcoinAddressForMainNet1 = privateKey.PubKey.GetAddress(Network.Main); | ||
var bitcoinAddressForTestNet1 = privateKey.PubKey.GetAddress(Network.TestNet); | ||
//Get the consistent each network type from the specific Bitcoin address. | ||
var mainNetFromBitcoinAddress = bitcoinAddressForMainNet.Network; | ||
var testNetFromBitcoinAddress = bitcoinAddressForTestNet.Network; | ||
``` | ||
> **Tip:** PracticingaBitcoin Programming on the MainNet makes mistakes more memorable. |
91 changes: 89 additions & 2 deletionsbitcoin_transfer/blockchain.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.