Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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:master
base:master
Choose a base branch
Loading
fromyoungminpark2559:master
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
72 commits
Select commitHold shift + click to select a range
d4c9968
Update private_key.md
youngminpark2559Nov 13, 2017
2845c76
Update comment
youngminpark2559Nov 13, 2017
fa5e560
Is adding "key" along with address more precise?
youngminpark2559Nov 13, 2017
6c1474e
Update private_key.md
youngminpark2559Nov 13, 2017
0833f44
Add contents about CombineSignatures()
youngminpark2559Nov 14, 2017
2360117
Merge pull request #1 from youngmtool/youngmtool-patch-1
youngminpark2559Nov 14, 2017
474bc99
Merge branch 'master' into master
nopara73Nov 15, 2017
7b44a07
Update bitcoin_address.md
youngminpark2559Nov 15, 2017
967fda6
Edit code block separation
youngminpark2559Nov 15, 2017
646bda1
Fix grammatical typos and add section separations
youngminpark2559Nov 16, 2017
3123abb
Fix multi-signing to multi-sig
youngminpark2559Nov 16, 2017
79d86de
Fix an indentation
youngminpark2559Nov 16, 2017
853b29e
Fix typo
youngminpark2559Nov 16, 2017
23ece61
Put a punctuation
youngminpark2559Nov 16, 2017
10c85ab
Add additional explanation
youngminpark2559Nov 16, 2017
43d0674
Update bitcoin_address.md
youngminpark2559Nov 16, 2017
089cb6e
Update bitcoin_address.md
youngminpark2559Nov 16, 2017
515eecc
Update bitcoin_address.md
youngminpark2559Nov 16, 2017
48dbef8
Add explanatory word
youngminpark2559Nov 16, 2017
2cc6024
Update transaction.md
youngminpark2559Nov 16, 2017
e049232
Update private_key.md
youngminpark2559Nov 16, 2017
9837130
Update spend_your_coin.md
youngminpark2559Nov 17, 2017
ec56222
Update spend_your_coin.md
youngminpark2559Nov 17, 2017
1c485af
Update spend_your_coin.md
youngminpark2559Nov 17, 2017
1017139
Please anyone check if it is how
youngminpark2559Nov 17, 2017
b94f168
Update spend_your_coin.md
youngminpark2559Nov 17, 2017
3e30802
Question.
youngminpark2559Nov 17, 2017
2323592
Update key_generation.md
youngminpark2559Nov 17, 2017
82b4288
Update key_generation.md
youngminpark2559Nov 17, 2017
5d4452e
Back some part(new Key(), privateKey) back to previous one in bitcoin…
youngminpark2559Nov 17, 2017
0adb917
Update bitcoin_address.md
youngminpark2559Nov 17, 2017
12c6cc9
Update key_generation.md
youngminpark2559Nov 17, 2017
e69ecb8
Update key_generation.md
youngminpark2559Nov 17, 2017
b13b5d7
Add explanation of a key object
youngminpark2559Nov 18, 2017
321004f
Update bitcoin_address.md
youngminpark2559Nov 18, 2017
2ff67fb
Update bitcoin_address.md
youngminpark2559Nov 18, 2017
e1df4c4
Update key_generation.md
youngminpark2559Nov 18, 2017
b40d3f1
Update mnemonic-code-for-hd-keys-bip39
youngminpark2559Nov 18, 2017
6bdbc55
Update p2pk[h]_pay_to_public_key_[hash].md
youngminpark2559Nov 18, 2017
4594789
Update arbitrary.md
youngminpark2559Nov 19, 2017
a5c85bc
Update arbitrary.md
youngminpark2559Nov 19, 2017
f194da2
Update arbitrary.md
youngminpark2559Nov 19, 2017
327348c
Merge branch 'master' into master
youngminpark2559Nov 19, 2017
abacd15
Update private_key.md
youngminpark2559Nov 19, 2017
9a1ab2a
Update private_key.md
youngminpark2559Nov 19, 2017
eccec6e
Update bitcoin_address.md
youngminpark2559Nov 20, 2017
7b85551
Update README.md
youngminpark2559Nov 20, 2017
980b98d
Update bitcoin_address.md
youngminpark2559Nov 20, 2017
0fe52c9
Update bitcoin_address.md
youngminpark2559Nov 20, 2017
53da20f
Update arbitrary.md
youngminpark2559Nov 20, 2017
ef6aa73
Update arbitrary.md
youngminpark2559Nov 20, 2017
42ce6ed
Update bitcoin_address.md
youngminpark2559Nov 21, 2017
284c111
Update bitcoin_address.md
youngminpark2559Nov 21, 2017
6fb599a
Update private_key.md
youngminpark2559Nov 21, 2017
e624bb2
Update transaction.md
youngminpark2559Nov 21, 2017
1a79cb6
Update blockchain.md
youngminpark2559Nov 22, 2017
3caa60d
Update blockchain.md
youngminpark2559Nov 22, 2017
e3b4f8d
Update blockchain.md
youngminpark2559Nov 22, 2017
2a6dcd7
Update blockchain.md
youngminpark2559Nov 22, 2017
d3c9b31
Update blockchain.md
youngminpark2559Nov 22, 2017
c83cce3
Update blockchain.md
youngminpark2559Nov 22, 2017
21726d5
Update the_blockchain_is_more_than_just_bitcoin.md
youngminpark2559Nov 22, 2017
c8abaee
Update proof_of_ownership_as_an_authentication_method.md
youngminpark2559Nov 23, 2017
cb2bd3b
Update proof_of_ownership_as_an_authentication_method.md
youngminpark2559Nov 23, 2017
a4c9f4a
Update spend_your_coin.md
youngminpark2559Nov 25, 2017
220b3de
Update colored_coins.md
youngminpark2559Nov 27, 2017
9458ef8
Update blockchain.md
youngminpark2559Nov 27, 2017
f8bcaa5
Update issuing_an_asset.md
youngminpark2559Nov 27, 2017
354703e
Update README.md
youngminpark2559Nov 27, 2017
8881763
Update bitcoin_address.md
youngminpark2559Nov 27, 2017
971b4f8
Update payment_script.md
youngminpark2559Nov 28, 2017
869b59f
Update private_key.md
youngminpark2559Nov 28, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletionsbitcoin_transfer/README.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
# 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.
#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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,133 @@
## Bitcoin address {#bitcoin-address}
# Chapter1. Bitcoin address {#bitcoin-address}

You know that your **Bitcoin Address** is what you share to the world to get paid.
## Section1. Bitcoin address

You know that your **Bitcoin address** is what you share to the world to get paid.
![](../assets/BitcoinAddress.png)
You probably know that your wallet software uses a **private key** to spend the money you receivedon this address.
You probably know that your wallet software uses a **private key** to spend the money you receivedfor sending the meney to the Bitcoin address.
![](../assets/PrivateKey.png)

The keysare not stored on the network and they can be generated without access to the Internet.
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
Key privateKey = new Key(); // generate a random private key
//Generate a random private key.
Key privateKey = new Key();
Console.WriteLine($"privateKey: {privateKey.ToString(Network.Main)}");
//Output:
//L3gyRGQ8Da1mMnDFkM9sFYbTV7P8hN8vHzmkALsfkyK7Wjfby5ZB
```
From the private key, we use a one-way cryptographic function, to generate a **public key**.
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**.

![](../assets/PrivKeyPubKey.png)
```cs
PubKey publicKey = privateKey.PubKey;
Console.WriteLine(publicKey); // 0251036303164f6c458e9f7abecb4e55e5ce9ec2b2f1d06d633c9653a07976560c
```
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".
> **Note:** You can acquire testnet coins quickly by using **faucets**. Just google "get testnet bitcoins".

You can easily get your**bitcoin address** from your public key and the**network** on which this address should be used.
You can easily get yourBitcoin address from your"public key" and the"network identifier" on which this address should be used.

![](../assets/PubKeyToAddr.png)

```cs
Console.WriteLine(publicKey.GetAddress(Network.Main)); // 1PUYsjwfNmX64wS368ZR5FMouTtUmvtmTY
Console.WriteLine(publicKey.GetAddress(Network.TestNet)); // n3zWAo2eBnxLr3ueohXnuAa8mTVBhxmPhq
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:**

**To be precise, a bitcoin address is made up of a version byte (which isdifferent on both networks) and your public key’s hash bytes. Both of these bytes are concatenated and then encoded into a Base58Check:**
In other words, it means that a generated Bitcoin address isalways in Base58Check encoding scheme.(If this is wrong, please edit it.)

![](../assets/PubKeyHashToBitcoinAddress.png)

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); // f6889b21b5540353a29ed18c45ea0031280c42cf
var mainNetAddress = publicKeyHash.GetAddress(Network.Main);
var testNetAddress = publicKeyHash.GetAddress(Network.TestNet);
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:**Apublic key hash is generated by using a SHA256 hash on the public key, then a RIPEMD160 hash on the result, using Big Endian notation. The function could look like this: RIPEMD160(SHA256(pubkey))
> **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))

The Base58Check encoding has some neat features, such as checksums to prevent typos and a lack of ambiguous characters such as '0' and 'O'.
The Base58Check encoding also provides a consistent way to determine the network of a given address; preventing a wallet from sending MainNet coins to a TestNet address.
## 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).

```cs
Console.WriteLine(mainNetAddress); // 1PUYsjwfNmX64wS368ZR5FMouTtUmvtmTY
Console.WriteLine(testNetAddress); // n3zWAo2eBnxLr3ueohXnuAa8mTVBhxmPhq
```
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:** Practicing Bitcoin Programming on MainNet makes mistakes more memorable.
> **Tip:** PracticingaBitcoin Programming on the MainNet makes mistakes more memorable.
91 changes: 89 additions & 2 deletionsbitcoin_transfer/blockchain.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,89 @@
## Blockchain {#blockchain}
# Chapter5. Blockchain {#blockchain}

You might have noticed that while we proved ownership of the spent TxOut, we have not yet proven the TxOut actually exists. This is where the main function of the Blockchain shines:
## Section1. Introducing the basic concepts and terms for the Blockchain system Part1

A Blockchain is composed of blocks. And each block shapes the chain by referencing the previous block. A block is composed of a block header and transaction(s).

See the illustration depicting a block and a blockchain, drawn by Young-min Park(Youngmtool), in the following link:
https://youngmtool.gitbooks.io/csharpdotnetconceptsandillustrations/blockchain.html

A header is composed of several data such as version(block version information.), prev_block(the hash value of the previous block, being used to reference the previous block.), merkle_root(the reference to a merkle tree collection which is a hash of all transactions related to this block.), timestamp(a timestamp recording when this block was created.), bits(the calculated difficulty target being used for this block.), nonce(the nonce used to generate this block… to allow variations of the header and compute different hashes.), txn_count(number of transaction entries, this value is always 0.).


Now let's see the transaction which is another part of the block along with the header.

The following is the looking of one transaction:
```json
{
"hash": "4788c5ef8ffd0463422bcafdfab240f5bf0be690482ceccde79c51cfce209edd",
"ver": 1,
"vin_sz": 1,
"vout_sz": 2,
"lock_time": 0,
"size": 259,
"in": [
{
"prev_out": {
"hash": "a6ae1beb8250a8fa6080749d5f82caee40f741d40957f0e8c4e4cc88830672ad",
"n": 1
},
"scriptSig": "3046022100aa39716861e508ae75ef577b3d83795a78d31cd72af0310b12ef8084cc16c9b8022100da72f62cdbd1b8d41cb4f8090e8c3b2929714279b3570962351dfbb739c2724601 0485c05717a0d35b2931c1395e9dcfffed3e67decff429477c48f6352da314c109ce0074bd1b991dd462ba16dbe9e4227193d35cc9342ea67f1b481054e345eef0"
},
{
"prev_out": {
"hash": "fbcc98b9601e9498c2ac097a493c6eb20473c438bf84891d572109335792198d",
"n": 1
},
"scriptSig": "3045022100fc8e579f4cabda1e26a294b3f7f227087b64ca2451155b8747bd1f6c96780d6d022041912d38512030e1ec1d3df6b8d91d8b9aa4c564642fd7cafc48f97fd550100101 0482d593f88a39160eaed14470ee4dad283c29e88d9abb904f953115b1a93d6f3881d6f8c29c53ddb30b2d1c6b657068d60a93ed240d5efca247836f6395807bcd"
},
{
"prev_out": {
"hash": "fbcc98b9601e9498c2ac097a493c6eb20473c438bf84891d572109335792198d",
"n": 3
},
"scriptSig": "3045022100fc8e579f4cabda1e26a294b3f7f227087b64ca2451155b8747bd1f6c96780d6d022041912d38512030e1ec1d3df6b8d91d8b9aa4c564642fd7cafc48f97fd550100101 0482d593f88a39160eaed14470ee4dad283c29e88d9abb904f953115b1a93d6f3881d6f8c29c53ddb30b2d1c6b657068d60a93ed240d5efca247836f6395807bcd"
}
],
"out": [
{
"value": "0.00010000",
"scriptPubKey": "OP_DUP OP_HASH160 edb82bd321c0c4b2b667c58e28ebc113d9bb38cd OP_EQUALVERIFY OP_CHECKSIG"
},
{
"value": "0.01440000",
"scriptPubKey": "OP_DUP OP_HASH160 21d77a260a7d8fb1b0064f9e3c0b4e46a44e8199 OP_EQUALVERIFY OP_CHECKSIG"
}
]
}
```
Note that one block can have multiple transactions.

A transaction is composed of several data:
1.TxIn.
A TxIn can have input(s). One input is composed of "prev_out" pointing to unspent output located in different transaction by specifying that output with the hash value of that transaction and the index number of that output in the correspond transaction and "scriptSig" playing a role of the signature.
2. TxOut.
A TxOut is composed of output(s). One output is composed of the value for an amount of coins which will be sent and a value of ScriptPubKey.
3. Other minimal data.
(1)hash is a transaction ID which is generated by twice hashing the entire of transaction(TxOut, TxIn, other minimal data)
(2)ver indicates the version of the transaction.
(3)vin_sz indicates the size of the TxIn.
(4)vout_sz indicates the size of the TxOut.
(5)lock_time
(6)size indicates the entire size of the transaction.


## Section2. Introducing the basic concepts and terms for the Blockchain system Part2

And each whole Blockchain located in each computer is termed by the ledger. And also each computer participating in the Bitcoin system network, with running the Bitcoin application and the whole blockchain which is termed the ledger, is termed the node.

And among the nodes, particular nodes which make the block by gathering transactions generated and transferred by the Bitcoin system clients, are termed the miner. And as of writing this book, the block should be created every average 10 minutes. Sometimes the block is created in 6 minutes after the previous block had been created. Somtimes the block is created in 13 minutes after the previous block had been created. It means that it's the average 10 minutes. And the 10 minutes which is one of protocols is for Bitcoin blockchain system. Other kinds of blockchain system can have different protocols as to this time. This particular 10 minutes which is needed to create a new block is specified for some purposes such as sustaining a stability of the Bitcoin system, preventing malcious attempts from being happened too frequently and so on.

And miner nodes compete to create the bloack and to append that bloack to the main chain. The block not appended into the main chain is termed the orphaned block. You only be able to get the coin from the coinbase transaction which is the first transaction of the newly created block and to get the mining fees generated by each transaction made by other Bitcoin system clients, in the block newly created by the corresponding miner who is getting fees in this block.


## Section3. More on the Blockchain system

You might have noticed that while we proved ownership of the unspent TxOut. And even more, prior to mentioning the proof of the ownership, note that we have not yet proven the TxOut actually exists. This is where the main function of the Blockchain shines:

The Blockchain is the database of all transactions that have happened since the the first Bitcoin transaction, known as the Genesis block. The Blockchain is duplicated all around the world. If you use Bitcoin Core, you have the whole Blockchain on your computer. Once a transaction appears on the Blockchain, it is very easy to prove its existence.

Expand All@@ -16,3 +99,7 @@ As a user, you can verify that a specific transaction exists in the Blockchain i

* Check the entire Blockchain, which at the time of this writing is several gigabytes in size.
* Ask for a partial Merkel tree, which are a few kilobytes in size. We will talk about merkel trees later in relation to Simple Payment Verification.


Ref.
https://en.bitcoin.it/wiki/Protocol_documentation#Block_Headers
Loading

[8]ページ先頭

©2009-2025 Movatter.jp