Skip to content

Commit 1305bcd

Browse files
committed
Merge branch 'master' into releases
2 parents cb0dd22 + 9ba7eff commit 1305bcd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1504
-287
lines changed

CONTRIBUTING.md

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,31 +43,33 @@ Consistency on the way classes are used is paramount to allow an easier understa
4343

4444
The design guidelines have quite a high abstraction level. These style guidelines are more concrete and easier to apply, and also more opinionated. The design guidelines mentioned above are the way we think about general software development and we believe they should be present in any software project.
4545

46-
### G0 - General: Default to Felixge's Style Guide
46+
### General
47+
48+
#### G0 - Default to Felixge's Style Guide
4749

4850
Follow this Node.js Style Guide: https://github.com/felixge/node-style-guide#nodejs-style-guide
4951

50-
### G1 - General: No Magic Numbers
52+
#### G1 - No Magic Numbers
5153

5254
Avoid constants in the code as much as possible. Magic strings are also magic numbers.
5355

54-
### G2 - General: Internal Objects should be Instances
56+
#### G2 - Internal Objects Should be Instances
5557

5658
If a class has a `publicKey` member, for instance, that should be a `PublicKey` instance.
5759

58-
### G3 - General: Internal amounts must be integers representing Satoshis
60+
#### G3 - Internal Amounts Must be Integers Representing Satoshis
5961

6062
Avoid representation errors by always dealing with satoshis. For conversion for frontends, use the `Unit` class.
6163

62-
### G4 - General: Internal network references must be Network instances
64+
#### G4 - Internal Network References Must be Network Instances
6365

6466
A special case for [G2](#g2---general-internal-objects-should-be-instances) all network references must be `Network` instances (see `lib/network.js`), but when returned to the user, its `.name` property should be used.
6567

66-
### G5 - General: Objects should display nicely in the console
68+
#### G5 - Objects Should Display Nicely in the Console
6769

6870
Write a `.inspect()` method so an instance can be easily debugged in the console.
6971

70-
### G6 - General: Naming Utility Namespaces
72+
#### G6 - Naming Utility Namespaces
7173

7274
Name them in CamelCase, as they are namespaces.
7375

@@ -80,7 +82,7 @@ DON'T:
8082
var bufferUtil = require('./util/buffer');
8183
```
8284

83-
### G7 - General: Standard Methods
85+
#### G7 - Standard Methods
8486

8587
When possible, bitcore objects should have standard methods on an instance prototype:
8688
* `toObject` - A plain JavaScript object that can be JSON stringified
@@ -93,7 +95,9 @@ These should have a matching static method that can be used for instantiation:
9395
* `fromString` - Should be able to instantiate with output from `toString`
9496
* `fromBuffer` - Should likewise be able to instantiate from output from `toBuffer`
9597

96-
### E1 - Errors: Use bitcore.Errors
98+
### Errors
99+
100+
#### E1 - Use bitcore.Errors
97101

98102
We've designed a structure for Errors to follow and are slowly migrating to it.
99103

@@ -103,9 +107,11 @@ Usage:
103107
* Whenever a new class is created, add a generic error for that class in `lib/errors/spec.js`.
104108
* Specific errors for that class should subclass that error. Take a look at the structure in `lib/errors/spec.js`, it should be clear how subclasses are generated from that file.
105109

106-
### E2 - Errors: Provide a `getValidationError` static method for classes
110+
#### E2 - Provide a `getValidationError` Static Method for Classes
111+
112+
### Interface
107113

108-
### I1 - Interface: Make Code that Fails Early
114+
#### I1 - Code that Fails Early
109115

110116
In order to deal with JavaScript's weak typing and confusing errors, we ask our code to fail as soon as possible when an unexpected input was provided.
111117

@@ -118,11 +124,11 @@ $.checkArgumentType(something, PrivateKey, 'something'); // The third argument i
118124
$.checkArgumentType(something, PrivateKey); // but it's optional (will show up as "(unknown argument)")
119125
```
120126

121-
### I2 - Interface: Permissive Constructors
127+
#### I2 - Permissive Constructors
122128

123129
Most classes have static methods named `fromBuffer`, `fromString`, `fromJSON`. Whenever one of those methods is provided, the constructor for that class should also be able to detect the type of the arguments and call the appropriate method.
124130

125-
### I3 - Interface: Method Chaining
131+
#### I3 - Method Chaining
126132

127133
For classes that have a mutable state, most of the methods that can be chained *SHOULD* be chained, allowing for interfaces that read well, like:
128134

@@ -134,7 +140,7 @@ var transaction = new Transaction()
134140
.sign(privkey);
135141
```
136142

137-
### I4 - Interface: Copy Constructors
143+
#### I4 - Copy Constructors
138144

139145
Constructors, when provided an instance of the same class, should:
140146
* Return the same object, if the instances of this class are immutable
@@ -156,7 +162,7 @@ function ImmutableClass(arg) {
156162
}
157163
```
158164

159-
### I5 - Interface: No new keyword for Constructors
165+
#### I5 - No New Keyword for Constructors
160166

161167
Constructors should not require to be called with `new`. This rule is not heavily enforced, but is a "nice to have".
162168

@@ -169,17 +175,19 @@ function NoNewRequired(args) {
169175
}
170176
```
171177

172-
### T1 - Testing: Tests Must be Written Elegantly
178+
### Testing
179+
180+
#### T1 - Tests Must be Written Elegantly
173181

174182
Style guidelines are not relaxed for tests. Tests are a good way to show how to use the library, and maintaining them is extremely necessary.
175183

176184
Don't write long tests, write helper functions to make them be as short and concise as possible (they should take just a few lines each), and use good variable names.
177185

178-
### T2 - Testing: Tests Must not be Random
186+
#### T2 - Tests Must not be Random
179187

180188
Inputs for tests should not be generated randomly. Also, the type and structure of outputs should be checked.
181189

182-
### T3 - Testing: Require 'bitcore' and look up classes from there
190+
#### T3 - Require 'bitcore' and Look up Classes from There
183191

184192
This helps to make tests more useful as examples, and more independent of where they are placed. This also helps prevent forgetting to include all submodules in the bitcore object.
185193

@@ -193,6 +201,20 @@ DON'T:
193201
var PublicKey = require('../lib/publickey');
194202
```
195203

204+
#### T4 - Data for Tests Included in a JSON File
205+
206+
If possible, data for tests should be included in a JSON file in the `test/data` directory. This improves interoperability with other libraries and keeps tests cleaner.
207+
208+
### Documentation
209+
210+
#### D1 - Guide and API Reference
211+
212+
All modules should include a developer guide and API reference. The API reference documentation is generated using JSDOC. Each function that exposes a public API should include a description, @return and @param, as appropriate. The general documentation guide for the module should be located in the `docs/guide` directory and is written in GitHub Flavored Markdown.
213+
214+
#### D2 - Proofread
215+
216+
Please proofread documentation to avoid unintentional spelling and grammatical mistakes before submitting a pull request.
217+
196218
## Pull Request Workflow
197219

198220
Our workflow is based on GitHub's pull requests. We use feature branches, prepended with: `test`, `feature`, `fix`, `refactor`, or `remove` according to the change the branch introduces. Some examples for such branches are:

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ simpleTx.sign(privateKey);
3232

3333
The complete docs are hosted here: [bitcore documentation](http://bitcore.io/guide/). There's also a [bitcore API reference](http://bitcore.io/api/) available generated from the JSDocs of the project, where you'll find low-level details on each bitcore utility.
3434

35-
[![Read the Developer Guide](http://bitpay.github.io/bitcore/images/read-the-developer-guide-btn.png)](http://bitcore.io/guide/) [![Read the API Reference](http://bitpay.github.io/bitcore/images/read-the-api-reference-btn.png)](http://bitcore.io/api/)
35+
[Read the Developer Guide](http://bitcore.io/guide/)
36+
37+
[Read the API Reference](http://bitcore.io/api/)
3638

3739
To get community assistance and ask for help with implementation questions, please use our [community forums](http://bitpaylabs.com/c/bitcore).
3840

bower.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
"license": "MIT",
2020
"ignore": [
2121
"**/.*",
22-
"node_modules",
23-
"bower_components",
24-
"tests"
22+
"CONTRIBUTING.md",
23+
"gulpfile.js",
24+
"lib",
25+
"index.js",
26+
"karma.conf.js",
27+
"npm-shrinkwrap.json",
28+
"test"
2529
]
2630
}

docs/guide/address.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: A simple interface to generate and validate a bitcoin address.
55

66
## Description
77

8-
Represents a bitcoin Address. Addresses are the most popular way to make bitcoin transactions. See [the official Bitcoin Wiki](https://en.bitcoin.it/wiki/Address) for technical background information.
8+
Represents a bitcoin address. Addresses are the most popular way to make bitcoin transactions. See [the official Bitcoin Wiki](https://en.bitcoin.it/wiki/Address) for technical background information.
99

1010
## Instantiate an Address
1111

docs/guide/block.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ description: A simple interface to parse and validate a bitcoin blocks.
55

66
## Description
77

8-
A Block instance represents the information of a block in the bitcoin network. Given a hexa or base64 string representation of the serialization of a block with its transactions, you can instantiate a Block instance. Methods are provided to calculate and check the merkle root hash (if enough data is provided), but transactions won't necessarily be valid spends, and this class won't validate them. A binary representation as a `Buffer` instance is also valid input for a Block's constructor.
8+
A Block instance represents the information of a block in the bitcoin network. Given a hexadecimal string representation of the serialization of a block with its transactions, you can instantiate a Block instance. Methods are provided to calculate and check the merkle root hash (if enough data is provided), but transactions won't necessarily be valid spends, and this class won't validate them. A binary representation as a `Buffer` instance is also valid input for a Block's constructor.
99

1010
```javascript
11-
1211
// instantiate a new block instance
1312
var block = new Block(hexaEncodedBlock);
1413

15-
// will verify that the correspending block transactions match the header
14+
// will verify that the corresponding block transactions match the header
1615
assert(block.validMerkleRoot());
1716

1817
// blocks have several properties
@@ -27,10 +26,9 @@ For detailed technical information about a block please visit [Blocks](https://e
2726

2827
## Block Header
2928

30-
Each instance of Block has a BlockHeader *(which can be instantiated seperately)*. The header has validation methods, to verify that the block.
29+
Each instance of Block has a BlockHeader *(which can be instantiated separately)*. The header has validation methods, to verify that the block.
3130

3231
```javascript
33-
3432
// will verify that the nonce demonstrates enough proof of work
3533
assert(block.header.validProofOfWork());
3634

docs/guide/browser.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
title: Browser Builds
2+
description: Guide to writing modules and optimizing browser bundles.
3+
---
4+
5+
# Browser Builds
6+
7+
When developing a module that will need to work in a browser and does not use the entire Bitcore namespace, it's recommended to narrow the scope of the requires to the particular modules that are needed. It will produce a smaller browser bundle as it will only include the JavaScript that is nessessary. Below is a quick tutorial that will use three modules.
8+
9+
## Tutorial
10+
11+
**Step 1**: Require Bitcore Modules
12+
13+
Here we require specific Bitcore modules that will be used in a `index.js` file:
14+
15+
```javascript
16+
17+
var PrivateKey = require('bitcore/lib/privatekey');
18+
var PublicKey = require('bitcore/lib/publickey');
19+
var Address = require('bitcore/lib/address');
20+
21+
// the rest of the module here
22+
23+
```
24+
25+
**Step 2**: Browserifying
26+
27+
Next we will generate a browser bundle using [browserify](https://www.npmjs.com/package/browserify) by running the command:
28+
29+
```bash
30+
browserify index.js -o index.browser.js
31+
```
32+
33+
This will output a file `index.browser.js` at around 700KB *(the entire Bitcore namespace is around 2MB)*.
34+
35+
**Step 3**: Uglifying
36+
37+
This can be further optimized by using [uglifyjs](https://www.npmjs.com/package/uglify-js), and running the command:
38+
39+
```bash
40+
uglifyjs index.browser.js --compress --mangle -o index.browser.min.js
41+
```
42+
43+
The resulting file `index.browser.min.js` in this case should be less than 300KB.
44+
45+
## Modules
46+
47+
Here is a list of some of the common modules:
48+
49+
```javascript
50+
var Address = require('bitcore/lib/address');
51+
var Block = require('bitcore/lib/block');
52+
var BlockHeader = require('bitcore/lib/blockheader');
53+
var HDPrivateKey = require('bitcore/lib/hdprivatekey');
54+
var HDPublicKey = require('bitcore/lib/hdpublickey');
55+
var PaymentProtocol = require('bitcore/lib/paymentprotocol');
56+
var PrivateKey = require('bitcore/lib/privatekey');
57+
var PublicKey = require('bitcore/lib/publickey');
58+
var Script = require('bitcore/lib/script');
59+
var Transaction = require('bitcore/lib/transaction');
60+
var URI = require('bitcore/lib/uri');
61+
var Unit = require('bitcore/lib/unit');
62+
```
63+
64+
For more informatation about each of the modules please see the [Bitcore Documentation](index.md).

docs/guide/crypto.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ The `bitcore.Crypto.Hash` namespace contains a set of hashes and utilities. Thes
2525

2626
## ECDSA
2727

28-
`bitcore.Crypto.ECDSA` contains a pure JavaScript implementation of the elliptic curve DSA signature scheme.
28+
`bitcore.Crypto.ECDSA` contains a pure JavaScript implementation of the elliptic curve DSA signature scheme based on [elliptic.js](https://github.com/indutny/elliptic).

docs/guide/ecies.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Bitcore implements [Elliptic Curve Integrated Encryption Scheme (ECIES)](http://
99

1010
For more information refer to the [bitcore-ecies](https://github.com/bitpay/bitcore-ecies) github repo.
1111

12-
## Instalation
12+
## Installation
1313

1414
ECIES is implemented as a separate module and you must add it to your dependencies:
1515

docs/guide/hierarchical.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ description: Lets you create and derive extended public and private keys accordi
33
---
44
# HDKeys
55

6-
## Hierarichically Derived Keys
6+
## Hierarchically Derived Keys
77

8-
Bitcore provides full support for [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki), allowing for many key management schemas that benefit from this property. Please be sure to read and understand the basic concepts and the warnings on that BIP before using these classes.
8+
Bitcore provides full support for [BIP32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki), allowing for many key management schemas that benefit from this property. Please be sure to read and understand the basic concepts and the warnings on that BIP before using these classes.
99

1010
## HDPrivateKey
1111

docs/guide/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ To get started, just `npm install bitcore` or `bower install bitcore`.
2929
* [Interface to the Bitcoin P2P network](peer.md)
3030
* [Managing a pool of peers](pool.md)
3131
* [Connecting to a bitcoind instance through JSON-RPC](jsonrpc.md)
32+
* [Connecting to a Insight instance to retrieve informetion](insight.md)
3233

3334
## Extra
3435
* [Crypto](crypto.md)
3536
* [Encoding](encoding.md)
3637
* [ECIES](ecies.md)
3738

39+
## Module Development
40+
* [Browser Builds](browser.md)
41+
3842
# Examples
3943

4044
## Create a Private Key

0 commit comments

Comments
 (0)