bitcore-wallet-service/README.md

194 lines
7.5 KiB
Markdown
Raw Normal View History

2015-02-17 13:51:15 -08:00
# bitcore-wallet-service
2015-02-20 10:15:08 -08:00
2015-02-20 10:14:00 -08:00
[![Build Status](https://img.shields.io/travis/bitpay/bitcore-wallet-service.svg?branch=master&style=flat-square)](https://travis-ci.org/bitpay/bitcore-wallet-service)
2015-02-21 14:22:21 -08:00
[![Coverage Status](https://coveralls.io/repos/bitpay/bitcore-wallet-service/badge.svg?branch=master)](https://coveralls.io/r/bitpay/bitcore-wallet-service?branch=master)
2015-02-20 10:12:37 -08:00
2015-02-17 14:09:28 -08:00
A Multisig HD Wallet Service, with minimun server trust.
2015-02-17 13:51:15 -08:00
# Quick Guide
2015-02-23 19:29:50 -08:00
``` shell
2015-02-24 07:51:14 -08:00
# Install dependencies
npm install
2015-02-17 13:51:15 -08:00
# Start the server
2015-02-24 07:51:14 -08:00
npm start
2015-02-17 13:51:15 -08:00
2015-02-17 22:55:34 -08:00
# Try the CLI interface
2015-02-17 13:51:15 -08:00
cd bit-wallet
2015-02-21 09:49:16 -08:00
# Create a 2-of-2 wallet (john.dat is the file where the wallet critical data will be stored, add -t for testnet)
2015-02-21 19:04:43 -08:00
./bit create 2-2 john
2015-02-17 13:51:15 -08:00
* Secret to share:
2015-02-22 06:16:29 -08:00
JevjEwaaxW6gdAZjqgWcimL525DR8zQsAXf4cscWDa8u1qKTN5eFGSFssuSvT1WySu4YYLYMUPT
2015-02-21 19:04:43 -08:00
./bit status
2015-02-17 13:51:15 -08:00
2015-02-21 09:49:16 -08:00
# Use -h or BIT_HOST to setup the base URL for your server.
2015-02-21 19:11:59 -08:00
# Use -f or BIT_FILE to setup the wallet data file
2015-02-17 22:55:34 -08:00
# Join the wallet from other copayer
2015-02-22 06:16:29 -08:00
./bit -f pete.dat join JevjEwaaxW6gdAZjqgWcimL525DR8zQsAXf4cscWDa8u1qKTN5eFGSFssuSvT1WySu4YYLYMUPT
2015-02-17 13:51:15 -08:00
export BIT_FILE=pete.dat
2015-02-21 19:11:59 -08:00
./bit -f pete.dat status
2015-02-24 05:45:38 -08:00
# Generate addresses to receive money
./bit address
* New Address 3xxxxxx
# Check your balance
2015-02-17 13:51:15 -08:00
./bit balance
2015-02-17 22:55:34 -08:00
2015-02-21 09:49:16 -08:00
# Spend coins. Amount can be specified in btc, bit or sat (default)
./bit send 1xxxxx 100bit "100 bits to mother"
2015-02-21 20:01:15 -08:00
# You can use 100bit or 0.00001btc or 10000sat. (Set up BIT_UNIT to btc/sat/bit so select output unit).
2015-02-17 22:55:34 -08:00
# List pending TX Proposals
2015-02-17 13:51:15 -08:00
./bit status
2015-02-17 22:55:34 -08:00
# Sign or reject TXs from other copayers
2015-02-21 19:11:59 -08:00
./bit -f pete.dat reject <id>
./bit -f pete.dat sign <id>
2015-02-24 05:45:38 -08:00
# List transaction history
a few minutes ago: => sent 100 bit ["100 bits to mother" by pete] (1 confirmations)
a day ago: <= received 1,400 bit (48 confirmations)
a day ago: <= received 300 bit (52 confirmations)
2015-02-17 22:55:34 -08:00
2015-02-24 05:45:38 -08:00
# List all commands:
./bit --help
2015-02-21 20:01:15 -08:00
2015-02-17 22:55:34 -08:00
2015-02-17 13:51:15 -08:00
```
2015-02-23 19:19:40 -08:00
# Local data
Copayers store its extended private key and their copayer's extended public key locally. We call this the ``Wallet Critical Data``. Extended private keys are never sent to the server.
# Password protection
Local data can be encrypted by the bit-wallet. Use the `-n` parameter to define the access level permited for no password operation. Available access levels are: `none` (password is required for everything, localfile is fully encrypted) `readonly`, `readwrite` and `full` (password is not ever required, local file is fully unencrypted) .
2015-02-23 19:31:07 -08:00
``` shell
2015-02-23 19:29:50 -08:00
# encrypts everything by default
2015-02-23 19:19:40 -08:00
bit create myWallet 2-3 --nopasswd none
Password:
2015-02-23 19:29:50 -08:00
# allows readonly operations without password (encrypts xpriv, and leave readonlySigningKey unencrypted)
2015-02-23 19:19:40 -08:00
bit create myWallet 2-3 -p --nopasswd readonly
2015-02-23 19:29:50 -08:00
# allows readwrite operations without password (only encrypts xpriv)
2015-02-23 19:19:40 -08:00
bit create myWallet 2-3 -p --nopasswd readwrite
```
2015-02-17 14:09:56 -08:00
2015-02-21 18:45:34 -08:00
# Advanced Operation
2015-02-21 19:11:59 -08:00
## Mobility
You can safely access a wallet from different devices. Just copy the wallet file (`bit.dat` by default). If you need to reduce the file to the mínimum (for example to fit it on a QR) or change it's access level (by removing certain data on it), see `export` in the following section.
2015-02-21 18:45:34 -08:00
## Export, with different access levels
It is possible to export a wallet with restricted access level. The levels are:
2015-02-23 19:29:50 -08:00
```
2015-02-21 18:45:34 -08:00
readonly : allows to read wallet data: balance, tx proposals
readwrite: + allows to create addresses and unsigned tx prposals
full : + allows sign tx prposals
2015-02-23 19:29:50 -08:00
```
2015-02-21 18:45:34 -08:00
`readonly` will only export the Wallet's Extended PublicKeys, and only the derived private key required for signing 'GET' request (readonly) to the server. `readwrite` will add the derived private key required for signing all other requests (as POST) so readwrite access will be possible. And `full` will export also the Extended Private Key, which is necesary for signing wallet's transactions. `bit import` can handle any for the levels correctly.
2015-02-23 19:31:07 -08:00
``` shell
2015-02-21 19:11:59 -08:00
# full access
2015-02-21 18:45:34 -08:00
bit export -o wallet.dat
2015-02-21 19:11:59 -08:00
# readonly access
2015-02-21 18:45:34 -08:00
bit export -o wallet.dat --access readonly
2015-02-21 19:11:59 -08:00
# readwrite access (can create addresses, propose transactions, reject TX, but does not have signing keys)
2015-02-21 18:45:34 -08:00
2015-02-21 19:11:59 -08:00
# Import the wallet , with giveng access level
2015-02-21 18:45:34 -08:00
bit import wallet.dat
2015-02-21 19:11:59 -08:00
# Export also support QR output:
bit export --qr
2015-02-21 18:45:34 -08:00
```
2015-02-23 19:31:07 -08:00
## If the wallet need to be migrated to other server, after importing the wallet use `bit-recreate` command
2015-02-21 18:45:34 -08:00
2015-02-23 19:29:50 -08:00
## Export / Import with a new given password (TO Be Done)
2015-02-23 19:31:07 -08:00
``` shell
2015-02-23 19:29:50 -08:00
bit export -o output.dat -e
bit import output.dat
2015-02-21 19:04:43 -08:00
```
2015-02-23 19:29:50 -08:00
2015-02-23 09:19:52 -08:00
# Airgapped Operation
2015-02-21 18:45:34 -08:00
2015-02-23 19:27:19 -08:00
Air gapped (non connected) devices are supported. This setup can be useful is maximun security is needed, to prevent private keys to get compromissed. In this setup a device is installed without network access, and transactions are signed off-line. Transactions can be pulled from the server using a `proxy` device, then downloaded to a pendrive to be moved to the air-gapped device, signed there and then moved back the `proxy` device to be send back to the server. Note that Private keys are generated off-line in the airgapped device.
2015-02-23 19:31:07 -08:00
``` shell
2015-02-23 19:27:19 -08:00
# On the Air-gapped device
airgapped$ bit genkey
airgapped$ bit export -o wallet.dat --readonly #(or --readwrite if you need the proxy to be able to propose transactions)
# On the proxy machine
proxy$ bit join secret -i wallet.dat
proxy$ bit balance
2015-02-22 19:48:55 -08:00
# Export pending transaction to be signed offline
2015-02-23 19:27:19 -08:00
proxy$ bit txproposals -o txproposals.dat
2015-02-21 18:45:34 -08:00
## Back to air-gapped device
2015-02-23 19:27:19 -08:00
# Check tx proposals:
airgapped$ bit txproposals -i txproposals.dat
# First time txproposals is running on the air gapped devices, the public keys of the copayers will be imported from the txproposals archive. That information is exported automatically by the proxy machine, and encrypted copayer's xpriv derivatives.
# Sign them
airgapped$ bit sign -i txproposals.dat -o txproposals-signed.dat
2015-02-22 19:48:55 -08:00
2015-02-21 18:45:34 -08:00
## Back to proxy machine
2015-02-23 19:27:19 -08:00
# Send signatures to the server
proxy$ bit sign -i txproposals-signed.dat
```
2015-02-17 23:01:34 -08:00
2015-02-17 14:09:28 -08:00
# Security Considerations
* Private keys are never send to the server. Copayers store them locally.
2015-02-21 09:49:16 -08:00
* Extended public keys are stored on the server. This allows the server to easily check wallet balance, send offline notifications to copayers, etc.
* During wallet creation a wallet secret is created by the initial copayer containg a private key. All copayers need to prove they have the secret by signing their information with this private key when joining the wallet. The secret should be shared using secured channels.
2015-02-17 22:55:34 -08:00
## All server responses are verified:
* Addresses, change addresses are derived independently and locally by the copayers from their local data.
2015-02-17 14:09:28 -08:00
* TX Proposals templates are signed by copayers, and verified by others, so the server cannot create / tamper them
2015-02-17 22:55:34 -08:00
## Notes
2015-02-21 09:49:16 -08:00
* A copayer could join the wallet more than once, and there is no mechanism to prevent it. Copayers should use the command 'confirm' to check other copayer's identity.
2015-02-17 22:55:34 -08:00
## In case the server is compromised
* It could be possible to see past (and future) wallet's transactions.
2015-02-21 09:49:16 -08:00
* It is not possible to spend wallet funds, since private keys are never sent nor stored at the server
* It is not possible to tamper tx proposals or wallet addresses since they are computed and verified by copayers
* Copayers could switch to another server using their local data (see `recreate` command). In this case only the wallet extended data will be lost (pending and past transaction proposals, some copayer metadata).
2015-02-17 22:55:34 -08:00
2015-02-21 18:45:34 -08:00
2015-02-21 19:11:59 -08:00
# Server API
## create a wallet
POST `/v1/wallets`
## join a wallet
POST `/v1/wallets/:id/copayers`
...
[To be completed, see expressapp.js]
2015-02-17 14:09:28 -08:00