You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+40-18Lines changed: 40 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,31 +43,33 @@ Consistency on the way classes are used is paramount to allow an easier understa
43
43
44
44
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.
45
45
46
-
### G0 - General: Default to Felixge's Style Guide
46
+
### General
47
+
48
+
#### G0 - Default to Felixge's Style Guide
47
49
48
50
Follow this Node.js Style Guide: https://github.com/felixge/node-style-guide#nodejs-style-guide
49
51
50
-
### G1 - General: No Magic Numbers
52
+
####G1 - No Magic Numbers
51
53
52
54
Avoid constants in the code as much as possible. Magic strings are also magic numbers.
53
55
54
-
### G2 - General: Internal Objects should be Instances
56
+
####G2 - Internal Objects Should be Instances
55
57
56
58
If a class has a `publicKey` member, for instance, that should be a `PublicKey` instance.
57
59
58
-
### G3 - General: Internal amounts must be integers representing Satoshis
60
+
####G3 - Internal Amounts Must be Integers Representing Satoshis
59
61
60
62
Avoid representation errors by always dealing with satoshis. For conversion for frontends, use the `Unit` class.
61
63
62
-
### G4 - General: Internal network references must be Network instances
64
+
####G4 - Internal Network References Must be Network Instances
63
65
64
66
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.
65
67
66
-
### G5 - General: Objects should display nicely in the console
68
+
####G5 - Objects Should Display Nicely in the Console
67
69
68
70
Write a `.inspect()` method so an instance can be easily debugged in the console.
69
71
70
-
### G6 - General: Naming Utility Namespaces
72
+
####G6 - Naming Utility Namespaces
71
73
72
74
Name them in CamelCase, as they are namespaces.
73
75
@@ -80,7 +82,7 @@ DON'T:
80
82
var bufferUtil =require('./util/buffer');
81
83
```
82
84
83
-
### G7 - General: Standard Methods
85
+
####G7 - Standard Methods
84
86
85
87
When possible, bitcore objects should have standard methods on an instance prototype:
86
88
*`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:
93
95
*`fromString` - Should be able to instantiate with output from `toString`
94
96
*`fromBuffer` - Should likewise be able to instantiate from output from `toBuffer`
95
97
96
-
### E1 - Errors: Use bitcore.Errors
98
+
### Errors
99
+
100
+
#### E1 - Use bitcore.Errors
97
101
98
102
We've designed a structure for Errors to follow and are slowly migrating to it.
99
103
@@ -103,9 +107,11 @@ Usage:
103
107
* Whenever a new class is created, add a generic error for that class in `lib/errors/spec.js`.
104
108
* 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.
105
109
106
-
### E2 - Errors: Provide a `getValidationError` static method for classes
110
+
#### E2 - Provide a `getValidationError` Static Method for Classes
111
+
112
+
### Interface
107
113
108
-
### I1 - Interface: Make Code that Fails Early
114
+
####I1 - Code that Fails Early
109
115
110
116
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.
111
117
@@ -118,11 +124,11 @@ $.checkArgumentType(something, PrivateKey, 'something'); // The third argument i
118
124
$.checkArgumentType(something, PrivateKey); // but it's optional (will show up as "(unknown argument)")
119
125
```
120
126
121
-
### I2 - Interface: Permissive Constructors
127
+
####I2 - Permissive Constructors
122
128
123
129
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.
124
130
125
-
### I3 - Interface: Method Chaining
131
+
####I3 - Method Chaining
126
132
127
133
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:
128
134
@@ -134,7 +140,7 @@ var transaction = new Transaction()
134
140
.sign(privkey);
135
141
```
136
142
137
-
### I4 - Interface: Copy Constructors
143
+
####I4 - Copy Constructors
138
144
139
145
Constructors, when provided an instance of the same class, should:
140
146
* Return the same object, if the instances of this class are immutable
@@ -156,7 +162,7 @@ function ImmutableClass(arg) {
156
162
}
157
163
```
158
164
159
-
### I5 - Interface: No new keyword for Constructors
165
+
####I5 - No New Keyword for Constructors
160
166
161
167
Constructors should not require to be called with `new`. This rule is not heavily enforced, but is a "nice to have".
162
168
@@ -169,17 +175,19 @@ function NoNewRequired(args) {
169
175
}
170
176
```
171
177
172
-
### T1 - Testing: Tests Must be Written Elegantly
178
+
### Testing
179
+
180
+
#### T1 - Tests Must be Written Elegantly
173
181
174
182
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.
175
183
176
184
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.
177
185
178
-
### T2 - Testing: Tests Must not be Random
186
+
####T2 - Tests Must not be Random
179
187
180
188
Inputs for tests should not be generated randomly. Also, the type and structure of outputs should be checked.
181
189
182
-
### T3 - Testing: Require 'bitcore' and look up classes from there
190
+
####T3 - Require 'bitcore' and Look up Classes from There
183
191
184
192
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.
185
193
@@ -193,6 +201,20 @@ DON'T:
193
201
var PublicKey =require('../lib/publickey');
194
202
```
195
203
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
+
196
218
## Pull Request Workflow
197
219
198
220
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:
Copy file name to clipboardExpand all lines: README.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,9 @@ simpleTx.sign(privateKey);
32
32
33
33
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.
34
34
35
-
[](http://bitcore.io/guide/)[](http://bitcore.io/api/)
35
+
[Read the Developer Guide](http://bitcore.io/guide/)
36
+
37
+
[Read the API Reference](http://bitcore.io/api/)
36
38
37
39
To get community assistance and ask for help with implementation questions, please use our [community forums](http://bitpaylabs.com/c/bitcore).
Copy file name to clipboardExpand all lines: docs/guide/address.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ description: A simple interface to generate and validate a bitcoin address.
5
5
6
6
## Description
7
7
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.
Copy file name to clipboardExpand all lines: docs/guide/block.md
+3-5Lines changed: 3 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,14 +5,13 @@ description: A simple interface to parse and validate a bitcoin blocks.
5
5
6
6
## Description
7
7
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.
9
9
10
10
```javascript
11
-
12
11
// instantiate a new block instance
13
12
var block =newBlock(hexaEncodedBlock);
14
13
15
-
// will verify that the correspending block transactions match the header
14
+
// will verify that the corresponding block transactions match the header
16
15
assert(block.validMerkleRoot());
17
16
18
17
// blocks have several properties
@@ -27,10 +26,9 @@ For detailed technical information about a block please visit [Blocks](https://e
27
26
28
27
## Block Header
29
28
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.
31
30
32
31
```javascript
33
-
34
32
// will verify that the nonce demonstrates enough proof of work
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:
Copy file name to clipboardExpand all lines: docs/guide/crypto.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,4 +25,4 @@ The `bitcore.Crypto.Hash` namespace contains a set of hashes and utilities. Thes
25
25
26
26
## ECDSA
27
27
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).
Copy file name to clipboardExpand all lines: docs/guide/hierarchical.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,9 @@ description: Lets you create and derive extended public and private keys accordi
3
3
---
4
4
# HDKeys
5
5
6
-
## Hierarichically Derived Keys
6
+
## Hierarchically Derived Keys
7
7
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.
0 commit comments