bitcore-wallet-service/README.md

204 lines
9.5 KiB
Markdown
Raw Normal View History

2015-03-04 09:31:52 -08:00
2015-03-04 10:07:28 -08:00
# bitcore-wallet-service
2015-03-04 10:17:16 -08:00
[![NPM Package](https://img.shields.io/npm/v/bitcore-wallet-service.svg?style=flat-square)](https://www.npmjs.org/package/bitcore-wallet-service)
2015-03-04 10:07:28 -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)
[![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-03-04 10:23:55 -08:00
A Multisig HD Bitcore Wallet Service.
2015-03-04 10:07:28 -08:00
# Description
Bitcore Wallet Service facilitates multisig HD wallets creation and operation through a (hopefully) simple and intuitive REST API.
2015-03-04 10:07:28 -08:00
2015-04-29 08:09:24 -07:00
BWS can usually be installed within minutes and accommodates all the needed infrastructure for peers in a multisig wallet to communicate and operate with minimum server trust.
2015-03-04 10:07:28 -08:00
2015-04-29 08:09:24 -07:00
See [Bitcore-wallet-client] (https://github.com/bitpay/bitcore-wallet-client) for the *official* client library that communicates to BWS and verifies its response. Also check [Bitcore-wallet] (https://github.com/bitpay/bitcore-wallet) for a simple CLI wallet implementation that relays on BWS.
2015-03-05 05:30:48 -08:00
2016-12-04 17:57:12 -08:00
BWS is been used in production enviroments for [Copay Wallet](https//copay.io), [Bitpay App wallet](https://bitpay.com/wallet) and others.
2015-03-04 10:07:28 -08:00
More about BWS at https://blog.bitpay.com/announcing-the-bitcore-wallet-suite/
2015-04-11 07:10:13 -07:00
2015-04-15 16:21:37 -07:00
# Install
```
2015-12-03 07:00:32 -08:00
npm install bitcore-wallet-service
2015-04-15 16:21:37 -07:00
npm start
```
This will launch the BWS service (with default settings) at `http://localhost:3232/bws/api`.
2015-04-22 10:34:52 -07:00
BWS needs mongoDB. You can configure the connection at `config.js`
2015-06-02 08:08:06 -07:00
BWS supports SSL and Clustering. For a detailed guide on installing BWS with extra features see [Installing BWS](https://github.com/bitpay/bitcore-wallet-service/blob/master/installation.md).
2015-04-15 16:21:37 -07:00
2016-11-30 05:53:33 -08:00
BWS uses by default a Request Rate Limitation to CreateWallet endpoint. If you need to modify it, check defaults.js' `Defaults.RateLimit`
2015-03-05 05:30:17 -08:00
# Security Considerations
2015-03-04 10:07:28 -08:00
* Private keys are never sent to BWS. Copayers store them locally.
* Extended public keys are stored on BWS. This allows BWS to easily check wallet balance, send offline notifications to copayers, etc.
* During wallet creation, the initial copayer creates a wallet secret that contains 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-05-17 16:53:24 -07:00
* A copayer could join the wallet more than once, and there is no mechanism to prevent this. See [wallet](https://github.com/bitpay/bitcore-wallet)'s confirm command, for a method for confirming copayers.
2015-03-05 05:28:17 -08:00
* All BWS responses are verified:
2015-03-04 10:07:28 -08:00
* Addresses and change addresses are derived independently and locally by the copayers from their local data.
* TX Proposals templates are signed by copayers and verified by others, so the BWS cannot create or tamper with them.
# REST API
## Authentication
In order to access a wallet, clients are required to send the headers:
```
x-identity
x-signature
```
Identity is the Peer-ID, this will identify the peer and its wallet. Signature is the current request signature, using `requestSigningKey`, the `m/1/1` derivative of the Extended Private Key.
See [Bitcore Wallet Client](https://github.com/bitpay/bitcore-wallet-client/blob/master/lib/api.js#L73) for implementation details.
2015-04-29 08:09:24 -07:00
## GET Endpoints
2015-03-04 10:07:28 -08:00
`/v1/wallets/`: Get wallet information
Returns:
* Wallet object. (see [fields on the source code](https://github.com/bitpay/bitcore-wallet-service/blob/master/lib/model/wallet.js)).
`/v1/txhistory/`: Get Wallet's transaction history
2015-03-20 13:02:59 -07:00
2015-03-20 13:04:06 -07:00
Optional Arguments:
2015-03-20 13:02:59 -07:00
* skip: Records to skip from the result (defaults to 0)
2015-03-20 13:04:06 -07:00
* limit: Total number of records to return (return all available records if not specified).
2015-03-04 10:07:28 -08:00
Returns:
2015-03-30 13:22:45 -07:00
* History of incoming and outgoing transactions of the wallet. The list is paginated using the `skip` & `limit` params. Each item has the following fields:
2015-03-20 13:04:06 -07:00
* action ('sent', 'received', 'moved')
* amount
* fees
* time
* addressTo
* confirmations
* proposalId
* creatorName
* message
* actions array ['createdOn', 'type', 'copayerId', 'copayerName', 'comment']
2015-03-04 10:07:28 -08:00
`/v1/txproposals/`: Get Wallet's pending transaction proposals and their status
Returns:
* List of pending TX Proposals. (see [fields on the source code](https://github.com/bitpay/bitcore-wallet-service/blob/master/lib/model/txproposal.js))
`/v1/addresses/`: Get Wallet's main addresses (does not include change addresses)
Returns:
2015-07-17 17:29:27 -07:00
* List of Addresses object: (https://github.com/bitpay/bitcore-wallet-service/blob/master/lib/model/address.js)). This call is mainly provided so the client check this addresses for incoming transactions (using a service like [Insight](https://insight.is)
2015-03-04 10:07:28 -08:00
`/v1/balance/`: Get Wallet's balance
Returns:
* totalAmount: Wallet's total balance
2015-07-20 15:50:07 -07:00
* lockedAmount: Current balance of outstanding transaction proposals, that cannot be used on new transactions.
* availableAmount: Funds available for new proposals.
* totalConfirmedAmount: Same as totalAmount for confirmed UTXOs only.
* lockedConfirmedAmount: Same as lockedAmount for confirmed UTXOs only.
* availableConfirmedAmount: Same as availableAmount for confirmed UTXOs only.
2015-03-06 10:05:05 -08:00
* byAddress array ['address', 'path', 'amount']: A list of addresses holding funds.
2015-07-20 15:50:07 -07:00
* totalKbToSendMax: An estimation of the number of KiB required to include all available UTXOs in a tx (including unconfirmed).
2015-03-04 10:07:28 -08:00
2015-04-29 08:09:24 -07:00
## POST Endpoints
2015-03-04 10:07:28 -08:00
`/v1/wallets/`: Create a new Wallet
Required Arguments:
* name: Name of the wallet
* m: Number of required peers to sign transactions
* n: Number of total peers on the wallet
* pubKey: Wallet Creation Public key to check joining copayer's signatures (the private key is unknown by BWS and must be communicated
by the creator peer to other peers).
Returns:
* walletId: Id of the new created wallet
2015-03-04 09:31:52 -08:00
`/v1/wallets/:id/copayers/`: Join a Wallet in creation
2015-03-04 10:07:28 -08:00
Required Arguments:
* walletId: Id of the wallet to join
* name: Copayer Name
2015-03-10 09:55:07 -07:00
* xPubKey - Extended Public Key for this copayer.
* requestPubKey - Public Key used to check requests from this copayer.
2015-04-29 08:11:29 -07:00
* copayerSignature - Signature used by other copayers to verify that the copayer joining knows the wallet secret.
2015-03-04 10:07:28 -08:00
Returns:
* copayerId: Assigned ID of the copayer (to be used on x-identity header)
* wallet: Object with wallet's information
`/v1/txproposals/`: Add a new transaction proposal
Required Arguments:
2015-07-20 15:50:07 -07:00
* toAddress: RCPT Bitcoin address.
2015-03-04 10:07:28 -08:00
* amount: amount (in satoshis) of the mount proposed to be transfered
* proposalsSignature: Signature of the proposal by the creator peer, using prososalSigningKey.
2015-07-20 15:50:07 -07:00
* (opt) message: Encrypted private message to peers.
* (opt) payProUrl: Paypro URL for peers to verify TX
* (opt) feePerKb: Use an alternative fee per KB for this TX.
* (opt) excludeUnconfirmedUtxos: Do not use UTXOs of unconfirmed transactions as inputs for this TX.
2015-03-04 10:07:28 -08:00
Returns:
* TX Proposal object. (see [fields on the source code](https://github.com/bitpay/bitcore-wallet-service/blob/master/lib/model/txproposal.js)). `.id` is probably needed in this case.
2015-03-04 09:31:52 -08:00
`/v1/addresses/`: Request a new main address from wallet
2015-03-04 10:07:28 -08:00
Returns:
2016-01-10 06:50:01 -08:00
* Address object: (https://github.com/bitpay/bitcore-wallet-service/blob/master/lib/model/address.js)). Note that `path` is returned so client can derive the address independently and check server's response.
2015-03-04 10:07:28 -08:00
2015-03-04 09:31:52 -08:00
`/v1/txproposals/:id/signatures/`: Sign a transaction proposal
2015-03-04 10:07:28 -08:00
Required Arguments:
* signatures: All Transaction's input signatures, in order of appearance.
Returns:
* TX Proposal object. (see [fields on the source code](https://github.com/bitpay/bitcore-wallet-service/blob/master/lib/model/txproposal.js)). `.status` is probably needed in this case.
2015-03-04 09:31:52 -08:00
`/v1/txproposals/:id/broadcast/`: Broadcast a transaction proposal
2015-03-04 10:07:28 -08:00
Returns:
* TX Proposal object. (see [fields on the source code](https://github.com/bitpay/bitcore-wallet-service/blob/master/lib/model/txproposal.js)). `.status` is probably needed in this case.
2015-03-04 09:31:52 -08:00
`/v1/txproposals/:id/rejections`: Reject a transaction proposal
2015-03-04 10:07:28 -08:00
Returns:
* TX Proposal object. (see [fields on the source code](https://github.com/bitpay/bitcore-wallet-service/blob/master/lib/model/txproposal.js)). `.status` is probably needed in this case.
2015-04-02 10:10:24 -07:00
`/v1/addresses/scan`: Start an address scan process looking for activity.
Optional Arguments:
* includeCopayerBranches: Scan all copayer branches following BIP45 recommendation (defaults to false).
2015-03-04 10:07:28 -08:00
2015-04-29 08:09:24 -07:00
## DELETE Endpoints
2015-03-04 09:31:52 -08:00
`/v1/txproposals/:id/`: Deletes a transaction proposal. Only the creator can delete a TX Proposal, and only if it has no other signatures or rejections
2015-03-04 10:07:28 -08:00
Returns:
* TX Proposal object. (see [fields on the source code](https://github.com/bitpay/bitcore-wallet-service/blob/master/lib/model/txproposal.js)). `.id` is probably needed in this case.
2016-01-19 05:05:54 -08:00
# Push Notifications
## Installation
In order to use push notifications service, you need install:
* [node-pushserver](https://www.npmjs.com/package/node-pushserver)
Recomended to complete config.js file:
* [GCM documentation to get your API key](https://developers.google.com/cloud-messaging/gcm)
* [Apple's Notification guide to know how to get your certificates for APN](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/Introduction.html)
## POST Endpoints
`/v1/pushnotifications/subscriptions/`: Adds subscriptions for push notifications service at database.
2015-03-04 10:07:28 -08:00
2016-01-19 05:05:54 -08:00
## DELETE Endopints
`/v1/pushnotifications/subscriptions/`: Remove subscriptions for push notifications service from database.
2015-03-04 10:07:28 -08:00
2015-03-04 09:31:52 -08:00
2015-02-17 14:09:28 -08:00
2015-03-03 21:03:56 -08:00
2015-03-04 10:07:28 -08:00