Bitcoin Wallet 入門


こんにちは、私はマルクス（[Twitter Account: @markusveeyola](https://twitter.com/markusveeyola)）です。現在、日本語を勉強しています。

私はBlockchainについて1ヶ月ほど勉強してきました。しかしまだ、blockchainの世界では色々な技術があり、他の技術も見てみることにしました。今週はBitcoin Walletについて調べたものを共有します。では、始めましょう！

#Bitcoin Walletとは
Bitcoin Walletは仮想的な財布です。その財布によって、トークンを保管できたり、購入したりすることができます。そのBitcoin Walletを仮想に作られたので、transactionを発生させる方法と保管する方法は違います。

Gmailのようなemail applicationはmailを受け取り、送信できます。送信のとき、自分のemail addressを使います。誰かがemailを送信できる前にrecipientが必要です。Bitcoin Walletも同じで、自分のaccountを作るときに、みなさんはunique public addressを貰います。お金の取引のためにそれを使います。
![is-bitcoin-anonymous.-wallet.png](https://qiita-image-store.s3.amazonaws.com/0/300940/7113d53a-cc4f-891e-92a7-3e6cf8ca79b2.png)
また、ログインするのに、passwordがなければなりません。Bitcoin Walletも同じで、userはpublic addressがあったら、private keyを貰います。身元を確認してトランザクションを作るためにそのkeyを使う必要があります。もちろん、userは誰にもにこのkeyを見せてはいけません。他のuserはuserのkeyを貰ったら、お金を盗むことができます。そして、それは不可逆的です。

Bitcoin Walletを確保するのに色々なprotocolを使う必要があります。BIP32とBIP39とBIP44はよく使います。

BIP protocolsについて説明します。

#BIPとは

The Bitcoin Improvement Proposal or BIP serves as a formal architecture of document that gives information on new features for bitcoin which can be used in the future. As of now, this is Bitcoin technology's standard medium for informing the community of users about the potential ideas and implementations for bitcoin.

BIPs can all differ by the type of details they offer. An example is the type, Standard Track BIP, which covers technical changes that are linked to transfer mechanisms. On the other hand, Informational BIP addressesdesign issues and general guidelines. Process BIP, however, covers the existing changes in the process of the bitcoin network.

The BIPs can be either accepted, rejected or deferred, and all this depends on the general consensus of the users.


##BIP 32

Bitcoin wallets allow multiple addresses to be generated, this is done to make it harder for anyone with malicious intent to hack your wallet. In a normal way, the first idea for generating a new private key is to just simply generate a random key. Bitcoin - QT is known for using this. 

But with BIP 32 protocol, the implementation is different. Without backing up the private key, a wallet user can always create a new key. The magic is that the second address key is not randomly generated but actually a derivative of the first one, the third is derived from the second and so on.

Learn more about BIP 32:
https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki


##BIP 44
It is a format for creating accounts and addresses. It is an implementation for deterministic wallets based on BIP32. So, it uses deterministic behavior of generating private keys but does it in a more organized way. It defines the traversing method in deriving the keys. In addition, it allows the managing of multiple coin types, accounts, external and internal chains per account and millions of addresses per chain.

Learn more about BIP 44:
https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki

##BIP 39

It is used to generate recovery phrases. It is a method for encoding 128-256 bits of random data into 12-24 word phrases from a list of interchangeable 2018 words, and then turn those phrases into a 64 byte hash.

A mnemonic code or sentence is superior for human interaction compared to the handling of raw binary or hexadecimal representations of a wallet seed. The sentence could be written on paper or spoken over the telephone.

Uses SHA512 to convert sentence to binary seed.

Learn more about BIP39:
https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki


There are still a lot of existing BIPs that you can read about, these three are just the standard protocols that are being used in when developing a bitcoin wallet. 

If you want to learn more about existing BIPs, here's the list:
https://github.com/bitcoin/bips

In a few moments, as you scroll down, I will be explaining about how to develop a bitcoin wallet. What are the features needed, and the tools that are required to make one. But for now, let's talk about another security topic, which is about Multi-Signature Wallets.

#Multi-Signature Walletとは

Multi signature wallet  is a special bitcoin wallet that require more than one person(private key) to sign the transaction of funds.
It requires the cooperation of multiple parties in order to do anything(trading or exchanging).
Mostly it involves 3 parties- one is the buyer , the recipient and the agent who acts as a mediator in the transactions. Each of them holds one private key. It is tougher for someone to steal more than one private keys, thus the multi signature wallet provides better security.
![1_ObToJDPaxeRYCZ8RBTp0Ug.jpeg](https://qiita-image-store.s3.amazonaws.com/0/300940/38c5a59f-98ad-5712-0447-20b5cadcd670.jpeg)

There are a lot of bitcoin wallets that supports multisignature, BitPay and CoPay are good examples. You can actually easily make your own multi-signature wallet in almost every bitcoin wallet, all you have to do is to make new “shared wallet.” From there you can set how many copayers can join your wallet, and how many is required to confirm a transaction. For the other users to join, you give them the invitation key of your created wallet. This is generated after creating it. 

#Developing a Bitcoin Wallet
In order for you to build your own bitcoin wallet, you have to know the fundamental features that a bitcoin wallet should have. Bitcoin is booming these days, so there are a lot of existing wallets already. And all these bitcoin wallets follow a standard. 

I will be showing 6 Features a Bitcoin should have when developing:

##6 Essential Features
![yes.png](https://qiita-image-store.s3.amazonaws.com/0/300940/5760713e-5af2-6b6a-adef-c072cd2f8434.png)
###1. Security
In creating a bitcoin wallet, because we are managing people’s money, this is the most important. We have to secure people’s data and we must secure their trust for us. To establish authorization, here are the following points:

your application can generate an account for the user. 
the account must generate a private key for signing and a public key to interact with other users.

- It can generate new key addresses.
- It can backup and restore your account if the user wants to migrate. 
- It can create a multi-signature wallet.

These features can be done by using the protocols i said earlier:

- BIP 32 - for generating a entropy master key and derive new keys from it.
- BIP 39 - for converting BIP 32 key to a mnemonic seed for backup and recovery.
- BIP 44 - for a comprehensive implementation of hierarchical deterministic key generation using BIP 32.

###2. Addresses
I have mentioned this earlier, this feature is different. whenever you do transaction with other people, your application should save the recipients. This makes it more convenient for the user. Like phone books in your phones.

###3. Paper Wallet Import
There are times that the user wants to store bitcoin physically. That’s why, the application should a feature that prints your wallet in a physical form. This stores a private key and bitcoin address on a paper. This allows the user to make transaction as well.

###4. Conversion Rates
Since we are making an application that handles cryptocurrency, of course your app should have a feature where it can do currency exchanges. This helps the user monitor the changes of the current rates of bitcoin.

###5. QR Code Scanner
When you transact with people directly, most of the time, you make transactions using QR code. Wallet addresses are too long and too complicated. That’s why scanning your QR code will make the transaction easier.

###6. Push Notifications
Another important feature for banking softwares are push notifications. Users want to know when something happens to their coins. For example, a request for payment, a successful sale into fiat, or large changes for coin prices. This makes it more convenient for users. 

##Tools for Development


For the technologies, there are a lot of tools that you can use to develop a bitcoin wallet. You can code them in different languages like C++, C#, Javascript, Java and etc. These days, developing a wallet has become more easy because you can use a lot of APIs and libraries. Example, there are [Bitcoin Core](https://bitcoin.org/en/release/v0.16.0), [BitcoinJS](https://github.com/bitcoinjs/bitcoinjs-lib), [BitcoinJ](https://bitcoinj.github.io/) for Java, [Electrum](https://github.com/spesmilo/electrum). Usually, bitcoin wallets are created using Electrum and React. These tools handle the communication of blockchain and the wallet. Also, it handles the sending and receiving of transactions. Since bitcoin only has cryptocurrency, features are just simple. That’s why, bitcoin wallets are very similar, but they only differ in extra features and quality service. 

If you want to get started right away, I can recommend a reference that you can read on to build your very own bitcoin wallet. 

Here is the link:
[How To Make Your First Bitcoin Application] (https://medium.com/zapchain-magazine/how-to-make-your-first-bitcoin-application-e2e07fb0078e)

#結論
And we're finished! Since this article is your head start, I'm sure you're all set to explore more about bitcoin wallets. There a lot of cool stuffs you can try out. As a piece of advice, if you want to understand how bitcoin wallets actually work, you can go deeper and get more into the technical side. Developing your first bitcoin wallet will give you a huge boost to get the grasp of it as a start.

If you find this article helpful, please leave an 「いいね」below! ありがとうございました！