Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
<img src="http://bitcore.io/css/images/module-channel.png" alt="bitcore payment channels" height="35">
# Payment Channels for Bitcore

[![NPM Package](https://img.shields.io/npm/v/bitcore-channel.svg?style=flat-square)](https://www.npmjs.org/package/bitcore-channel)
[![Build Status](https://img.shields.io/travis/bitpay/bitcore-channel.svg?branch=master&style=flat-square)](https://travis-ci.org/bitpay/bitcore-channel)
[![Coverage Status](https://img.shields.io/coveralls/bitpay/bitcore-channel.svg?style=flat-square)](https://coveralls.io/r/bitpay/bitcore-channel)


A module for [bitcore][bitcore] that implements [Payment Channels][channel]. Payment channels (sometimes referred as micropayment channels) are a type of smart contracts that allow rapidly adjusting bitcoin transactions. This can be used to do trustless simultaneous payments with a service provider without the need of an intermediary, and some other applications.

See [the main bitcore repo][bitcore] or the [bitcore guide on Payment Channels](http://bitcore.io/guide/module/channel/index.html) for more information.

## Getting Started

```sh
npm install bitcore-lib
npm install bitcore-channel
```

```sh
bower install bitcore-lib
bower install bitcore-channel
```

## Contributing

See [CONTRIBUTING.md](https://github.com/bitpay/bitcore/blob/master/CONTRIBUTING.md) on the main bitcore repo for information about how to contribute.
Expand Down
8 changes: 8 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ Payment channels are implemented as a separate module and you must add it to you
For node projects:

```
npm install bitcore-lib --save
npm install bitcore-channel --save
```

For client-side projects:

```
bower install bitcore-lib --save
bower install bitcore-channel --save
```

Expand All @@ -24,12 +26,18 @@ Let's start with an overview of how to use the Consumer side. Let's assume that
We also have a final address that we'll use as a "change" address (sending here any funds that we didn't transact with the Provider). We'll call this the "refund" address, as it will also be the address where the refund will get to in case the contract is cancelled.

```javascript
var bitcore = require('bitcore-lib');
var Consumer = require('bitcore-channel').Consumer;
var providerPublicKey = '027f10e67bea70f847b3ab92c18776c6a97a78f84def158afc31fd98513d42912e';
var refundAddress = 'mzCXqcsLBerwyoRZzBFQELHaJ1ZtBSxxe6';
var providerAddress = 'mrCHmWgn54hJNty2srFF4XLmkey5GnCv5m';

// Make sure to save this, a good way is to use the bitcore-mnemonic library or
// export a WIF format with fundingKey.toWIF()
var fundingKey = new bitcore.PrivateKey();

var consumer = new Consumer({
fundingKey: fundingKey,
network: 'testnet',
providerPublicKey: providerPublicKey,
providerAddress: providerAddress,
Expand Down
4 changes: 2 additions & 2 deletions examples/01.createChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var insight = new bitcore.transport.explorers.Insight();
insight.getUnspentUtxos(consumer.fundingAddress, function(err, utxos) {
consumer.processFunding(utxos);
consumer.commitmentTx._updateChangeOutput();
fs.writeFileSync('unsigned.refund.log', consumer.setupRefund().toJSON());
fs.writeFileSync('unsigned.refund.log', JSON.stringify(consumer.setupRefund()));
console.log(consumer.commitmentTx.toString());
fs.writeFileSync('commitment.log', consumer.commitmentTx.toJSON());
fs.writeFileSync('commitment.log', JSON.stringify(consumer.commitmentTx));
});
2 changes: 1 addition & 1 deletion examples/02.signRefund.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ var provider = new Provider({

var refund = JSON.parse(fs.readFileSync('unsigned.refund.log'));

fs.writeFileSync('signed.refund.log', provider.signRefund(refund).refund.toJSON());
fs.writeFileSync('signed.refund.log', JSON.stringify(provider.signRefund(refund).refund));

2 changes: 1 addition & 1 deletion examples/04.firstPayment.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ var refund = JSON.parse(fs.readFileSync('signed.refund.log'));
if (consumer.validateRefund(refund)) {
consumer.incrementPaymentBy(10400);
console.log(consumer.paymentTx.toString());
fs.writeFileSync('firstpayment.log', consumer.paymentTx.toJSON());
fs.writeFileSync('firstpayment.log', JSON.stringify(consumer.paymentTx));
}