Skip to content

Commit b696d1b

Browse files
committed
Updated bitcoinjs-lib to version 5.0.5.
1 parent 4b73859 commit b696d1b

File tree

146 files changed

+3407
-15460
lines changed

Some content is hidden

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

146 files changed

+3407
-15460
lines changed

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
# 5.0.4
2+
__added__
3+
- low R value support for ECPair, bip32, and TransactionBuilder (default off) via `txb.setLowR()` (#1385)
4+
5+
__fixed__
6+
- Fixed Various TypeScript types that have been pushed out since v5.0.0 (#1388)
7+
8+
# 5.0.0
9+
__added__
10+
- TypeScript support (#1319)
11+
- `Block.prototype.checkTxRoots` will check the merkleRoot and witnessCommit if it exists against the transactions array. (e52abec) (0426c66)
12+
13+
__changed__
14+
- `Transaction.prototype.getHash` now has `forWitness?: boolean` which when true returns the hash for wtxid (a652d04)
15+
- `Block.calculateMerkleRoot` now has `forWitness?: boolean` which when true returns the witness commit (a652d04)
16+
17+
__removed__
18+
- `Block.prototype.checkMerkleRoot` was removed, please use `checkTxRoots` (0426c66)
19+
20+
# 4.0.5
21+
__fixed__
22+
- Fixed bug where Angular apps break due to lack of crypto at build time. Reverted #1373 and added (6bead5d).
23+
24+
# 4.0.4
25+
__fixed__
26+
- Fixed bug where Electron v4 breaks due to lack of `'rmd160'` alias for ripemd160 hash. (#1373)
27+
128
# 4.0.3
229
__fixed__
330
- Fixed `TransactionBuilder` to require that the Transaction has outputs before signing (#1151)

README.md

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@
22
[![Build Status](https://travis-ci.org/bitcoinjs/bitcoinjs-lib.png?branch=master)](https://travis-ci.org/bitcoinjs/bitcoinjs-lib)
33
[![NPM](https://img.shields.io/npm/v/bitcoinjs-lib.svg)](https://www.npmjs.org/package/bitcoinjs-lib)
44

5-
[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
5+
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
66

7-
This is a React Native compatible version of [bitcoinjs-lib](https://github.com/bitcoinjs/bitcoinjs-lib), a javascript Bitcoin library for node.js and browsers.
7+
This is a React Native compatible version of [bitcoinjs-lib](https://github.com/bitcoinjs/bitcoinjs-lib), a javascript Bitcoin library for node.js and browsers. Written in TypeScript, but committing the JS files to verify.
88

99
Released under the terms of the [MIT LICENSE](LICENSE).
1010

11+
## Should I use this in production?
12+
If you are thinking of using the *master* branch of this library in production, **stop**.
13+
Master is not stable; it is our development branch, and [only tagged releases may be classified as stable](https://github.com/coreyphillips/rn-bitcoinjs-lib/tags).
14+
15+
1116
## Can I trust this code?
1217
> Don't trust. Verify.
1318
14-
You shouldn't trust or rely on this repo for anything other than testing. To setup bitcoinjs-lib (4.0.3) in your RN project, please follow the how-to below:
15-
[RN BitcoinJS-Lib (4.0.3) Setup](https://gist.github.com/coreyphillips/723a718f3630f965a83007a81afe5926)
19+
You shouldn't trust or rely on this repo for anything other than testing. To setup bitcoinjs-lib (5.0.5) in your RN project, please follow the how-to below:
20+
[RN BitcoinJS-Lib (5.0.5) Setup](https://gist.github.com/coreyphillips/9719d7e4b1f6042b993f548d2083cee8)
1621

1722
If you have any difficulty with the setup instructions below and need a repo for reference, feel free to clone, review and experiment with the pre-built RN repo here: [RNBitcoinJS](https://github.com/coreyphillips/RNBitcoinJS)
1823

@@ -23,7 +28,7 @@ Mistakes and bugs happen, but with your help in resolving and reporting [issues]
2328
- Easy to audit and verify,
2429
- Tested, with test coverage >95%,
2530
- Advanced and feature rich,
26-
- Standardized, using [standard](https://github.com/standard/standard) and Node `Buffer`'s throughout, and
31+
- Standardized, using [prettier](https://github.com/prettier/prettier) and Node `Buffer`'s throughout, and
2732
- Friendly, with a strong and helpful community, ready to answer questions.
2833

2934
## Documentation
@@ -35,6 +40,12 @@ Presently, we do not have any formal documentation other than our [examples](ht
3540
yarn add rn-bitcoinjs-lib
3641
```
3742

43+
Typically we support the [Node Maintenance LTS version](https://github.com/nodejs/Release).
44+
If in doubt, see the [.travis.yml](.travis.yml) for what versions are used by our continuous integration tests.
45+
46+
**WARNING**: We presently don't provide any tooling to verify that the release on `npm` matches GitHub. As such, you should verify anything downloaded by `npm` against your own verified copy.
47+
48+
3849
## Setup
3950

4051
### React Native
@@ -123,30 +134,7 @@ Use [bitcoinjs-lib](https://github.com/bitcoinjs/bitcoinjs-lib)
123134
Use [bitcoinjs-lib](https://github.com/bitcoinjs/bitcoinjs-lib)
124135

125136
### Typescript or VSCode users
126-
Type declarations for Typescript [are available](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/0897921174860ec3d5318992d2323b3ae8100a68/types/bitcoinjs-lib) for version `^3.0.0` of the library.
127-
128-
``` bash
129-
npm install @types/bitcoinjs-lib
130-
```
131-
132-
For VSCode (and other editors), it is advised to install the type declarations, as Intellisense uses that information to help you code (autocompletion, static analysis).
133-
134-
**WARNING**: These Typescript definitions are not maintained by the maintainers of this repository, and are instead maintained at [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped).
135-
Please report any issues or problems there.
136-
137-
138-
### Flow
139-
[Flow-type](https://flowtype.org/) definitions for are available in the [flow-*typed* repository](https://github.com/flowtype/flow-typed/tree/master/definitions/npm/bitcoinjs-lib_v2.x.x) for version `^2.0.0` of the library.
140-
141-
You can [download them directly](https://github.com/flowtype/flow-typed/blob/master/definitions/npm/bitcoinjs-lib_v2.x.x/flow_v0.17.x-/bitcoinjs-lib_v2.x.x.js), or using the flow-typed CLI:
142-
143-
``` bash
144-
npm install -g flow-typed
145-
flow-typed install -f 0.27 bitcoinjs-lib@2.2.0
146-
```
147-
148-
**WARNING**: These flow-typed definitions are not maintained by the maintainers of this repository.
149-
137+
Type declarations for Typescript are included in this library. Normal installation should include all the needed type information.
150138

151139
## Examples
152140
The below examples are implemented as integration tests, they should be very easy to understand.
@@ -184,6 +172,11 @@ Some examples interact (via HTTPS) with a 3rd Party Blockchain Provider (3PBP).
184172
- [Create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the future)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.js)
185173
- [Create (and broadcast via 3PBP) a Transaction where Alice and Bob can redeem the output at any time](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.js)
186174
- [Create (but fail to broadcast via 3PBP) a Transaction where Alice attempts to redeem before the expiry](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.js)
175+
- [Create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the future) (simple CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.js)
176+
- [Create (but fail to broadcast via 3PBP) a Transaction where Alice attempts to redeem before the expiry (simple CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.js)
177+
- [Create (and broadcast via 3PBP) a Transaction where Bob and Charles can send (complex CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.js)
178+
- [Create (and broadcast via 3PBP) a Transaction where Alice (mediator) and Bob can send after 2 blocks (complex CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.js)
179+
- [Create (and broadcast via 3PBP) a Transaction where Alice (mediator) can send after 5 blocks (complex CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.js)
187180

188181
If you have a use case that you feel could be listed here, please [ask for it](https://github.com/bitcoinjs/bitcoinjs-lib/issues/new)!
189182

package.json

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "rn-bitcoinjs-lib",
3-
"version": "4.0.3-1",
3+
"version": "5.0.5",
44
"description": "Client-side Bitcoin JavaScript library",
55
"main": "./src/index.js",
6+
"types": "./types/index.d.ts",
67
"engines": {
78
"node": ">=8.0.0"
89
},
@@ -14,34 +15,48 @@
1415
"bitcoinjs"
1516
],
1617
"scripts": {
17-
"coverage-report": "nyc report --reporter=lcov",
18-
"coverage-html": "nyc report --reporter=html",
19-
"coverage": "nyc --check-coverage --branches 90 --functions 90 mocha",
20-
"integration": "mocha --timeout 50000 test/integration/",
21-
"standard": "standard",
22-
"test": "npm run standard && npm run coverage",
23-
"unit": "mocha"
18+
"build": "npm run clean && tsc -p ./tsconfig.json && npm run formatjs",
19+
"clean": "rimraf src types",
20+
"coverage-report": "npm run build && npm run nobuild:coverage-report",
21+
"coverage-html": "npm run build && npm run nobuild:coverage-html",
22+
"coverage": "npm run build && npm run nobuild:coverage",
23+
"format": "npm run prettier -- --write",
24+
"formatjs": "npm run prettierjs -- --write > /dev/null 2>&1",
25+
"format:ci": "npm run prettier -- --check && npm run prettierjs -- --check",
26+
"gitdiff:ci": "npm run build && git diff --exit-code",
27+
"integration": "npm run build && npm run nobuild:integration",
28+
"lint": "tslint -p tsconfig.json -c tslint.json",
29+
"nobuild:coverage-report": "nyc report --reporter=lcov",
30+
"nobuild:coverage-html": "nyc report --reporter=html",
31+
"nobuild:coverage": "nyc --check-coverage --branches 90 --functions 90 --lines 90 mocha",
32+
"nobuild:integration": "mocha --timeout 50000 test/integration/",
33+
"nobuild:unit": "mocha",
34+
"prettier": "prettier 'ts_src/**/*.ts' --ignore-path ./.prettierignore",
35+
"prettierjs": "prettier 'src/**/*.js' --ignore-path ./.prettierignore",
36+
"test": "npm run build && npm run format:ci && npm run lint && npm run nobuild:coverage",
37+
"unit": "npm run build && npm run nobuild:unit"
2438
},
2539
"repository": {
2640
"type": "git",
27-
"url": "https://github.com/coreyphillips/rn-bitcoinjs-lib.git"
41+
"url": "https\n \"dependencies\": {://github.com/bitcoinjs/bitcoinjs-lib.git"
2842
},
2943
"files": [
30-
"src"
44+
"src",
45+
"types"
3146
],
3247
"dependencies": {
48+
"@types/node": "10.12.18",
3349
"bech32": "^1.1.2",
34-
"bip32": "^1.0.0",
50+
"bip32": "^2.0.3",
3551
"bip66": "^1.1.0",
3652
"bitcoin-ops": "^1.4.0",
3753
"bs58check": "^2.0.0",
3854
"create-hash": "^1.1.0",
3955
"create-hmac": "^1.1.3",
4056
"merkle-lib": "^2.0.10",
4157
"pushdata-bitcoin": "^1.0.1",
42-
"react-native-randombytes": "^3.0.0",
43-
"safe-buffer": "^5.1.1",
44-
"tiny-secp256k1": "^1.0.0",
58+
"react-native-randombytes": "^3.5.3",
59+
"tiny-secp256k1": "^1.1.1",
4560
"typeforce": "^1.11.3",
4661
"varuint-bitcoin": "^1.0.4",
4762
"wif": "^2.0.1"
@@ -56,9 +71,12 @@
5671
"hoodwink": "^2.0.0",
5772
"minimaldata": "^1.0.2",
5873
"mocha": "^5.2.0",
59-
"nyc": "^11.8.0",
74+
"nyc": "^14.1.1",
75+
"prettier": "1.16.4",
6076
"proxyquire": "^2.0.1",
61-
"standard": "^11.0.1"
77+
"rimraf": "^2.6.3",
78+
"tslint": "^5.16.0",
79+
"typescript": "3.2.2"
6280
},
6381
"license": "MIT",
6482
"react-native": {
@@ -81,4 +99,4 @@
8199
"stream": "stream-browserify",
82100
"vm": "vm-browserify"
83101
}
84-
}
102+
}

src/address.js

Lines changed: 73 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,91 @@
1-
const Buffer = require('safe-buffer').Buffer
2-
const bech32 = require('bech32')
3-
const bs58check = require('bs58check')
4-
const bscript = require('./script')
5-
const networks = require('./networks')
6-
const typeforce = require('typeforce')
7-
const types = require('./types')
8-
const payments = require('./payments')
9-
10-
function fromBase58Check (address) {
11-
const payload = bs58check.decode(address)
12-
1+
'use strict';
2+
Object.defineProperty(exports, '__esModule', { value: true });
3+
const networks = require('./networks');
4+
const payments = require('./payments');
5+
const bscript = require('./script');
6+
const types = require('./types');
7+
const bech32 = require('bech32');
8+
const bs58check = require('bs58check');
9+
const typeforce = require('typeforce');
10+
function fromBase58Check(address) {
11+
const payload = bs58check.decode(address);
1312
// TODO: 4.0.0, move to "toOutputScript"
14-
if (payload.length < 21) throw new TypeError(address + ' is too short')
15-
if (payload.length > 21) throw new TypeError(address + ' is too long')
16-
17-
const version = payload.readUInt8(0)
18-
const hash = payload.slice(1)
19-
20-
return { version: version, hash: hash }
13+
if (payload.length < 21) throw new TypeError(address + ' is too short');
14+
if (payload.length > 21) throw new TypeError(address + ' is too long');
15+
const version = payload.readUInt8(0);
16+
const hash = payload.slice(1);
17+
return { version, hash };
2118
}
22-
23-
function fromBech32 (address) {
24-
const result = bech32.decode(address)
25-
const data = bech32.fromWords(result.words.slice(1))
26-
19+
exports.fromBase58Check = fromBase58Check;
20+
function fromBech32(address) {
21+
const result = bech32.decode(address);
22+
const data = bech32.fromWords(result.words.slice(1));
2723
return {
2824
version: result.words[0],
2925
prefix: result.prefix,
30-
data: Buffer.from(data)
31-
}
26+
data: Buffer.from(data),
27+
};
3228
}
33-
34-
function toBase58Check (hash, version) {
35-
typeforce(types.tuple(types.Hash160bit, types.UInt8), arguments)
36-
37-
const payload = Buffer.allocUnsafe(21)
38-
payload.writeUInt8(version, 0)
39-
hash.copy(payload, 1)
40-
41-
return bs58check.encode(payload)
29+
exports.fromBech32 = fromBech32;
30+
function toBase58Check(hash, version) {
31+
typeforce(types.tuple(types.Hash160bit, types.UInt8), arguments);
32+
const payload = Buffer.allocUnsafe(21);
33+
payload.writeUInt8(version, 0);
34+
hash.copy(payload, 1);
35+
return bs58check.encode(payload);
4236
}
43-
44-
function toBech32 (data, version, prefix) {
45-
const words = bech32.toWords(data)
46-
words.unshift(version)
47-
48-
return bech32.encode(prefix, words)
37+
exports.toBase58Check = toBase58Check;
38+
function toBech32(data, version, prefix) {
39+
const words = bech32.toWords(data);
40+
words.unshift(version);
41+
return bech32.encode(prefix, words);
4942
}
50-
51-
function fromOutputScript (output, network) {
52-
network = network || networks.bitcoin
53-
54-
try { return payments.p2pkh({ output, network }).address } catch (e) {}
55-
try { return payments.p2sh({ output, network }).address } catch (e) {}
56-
try { return payments.p2wpkh({ output, network }).address } catch (e) {}
57-
try { return payments.p2wsh({ output, network }).address } catch (e) {}
58-
59-
throw new Error(bscript.toASM(output) + ' has no matching Address')
43+
exports.toBech32 = toBech32;
44+
function fromOutputScript(output, network) {
45+
// TODO: Network
46+
network = network || networks.bitcoin;
47+
try {
48+
return payments.p2pkh({ output, network }).address;
49+
} catch (e) {}
50+
try {
51+
return payments.p2sh({ output, network }).address;
52+
} catch (e) {}
53+
try {
54+
return payments.p2wpkh({ output, network }).address;
55+
} catch (e) {}
56+
try {
57+
return payments.p2wsh({ output, network }).address;
58+
} catch (e) {}
59+
throw new Error(bscript.toASM(output) + ' has no matching Address');
6060
}
61-
62-
function toOutputScript (address, network) {
63-
network = network || networks.bitcoin
64-
65-
let decode
61+
exports.fromOutputScript = fromOutputScript;
62+
function toOutputScript(address, network) {
63+
network = network || networks.bitcoin;
64+
let decodeBase58;
65+
let decodeBech32;
6666
try {
67-
decode = fromBase58Check(address)
67+
decodeBase58 = fromBase58Check(address);
6868
} catch (e) {}
69-
70-
if (decode) {
71-
if (decode.version === network.pubKeyHash) return payments.p2pkh({ hash: decode.hash }).output
72-
if (decode.version === network.scriptHash) return payments.p2sh({ hash: decode.hash }).output
69+
if (decodeBase58) {
70+
if (decodeBase58.version === network.pubKeyHash)
71+
return payments.p2pkh({ hash: decodeBase58.hash }).output;
72+
if (decodeBase58.version === network.scriptHash)
73+
return payments.p2sh({ hash: decodeBase58.hash }).output;
7374
} else {
7475
try {
75-
decode = fromBech32(address)
76+
decodeBech32 = fromBech32(address);
7677
} catch (e) {}
77-
78-
if (decode) {
79-
if (decode.prefix !== network.bech32) throw new Error(address + ' has an invalid prefix')
80-
if (decode.version === 0) {
81-
if (decode.data.length === 20) return payments.p2wpkh({ hash: decode.data }).output
82-
if (decode.data.length === 32) return payments.p2wsh({ hash: decode.data }).output
78+
if (decodeBech32) {
79+
if (decodeBech32.prefix !== network.bech32)
80+
throw new Error(address + ' has an invalid prefix');
81+
if (decodeBech32.version === 0) {
82+
if (decodeBech32.data.length === 20)
83+
return payments.p2wpkh({ hash: decodeBech32.data }).output;
84+
if (decodeBech32.data.length === 32)
85+
return payments.p2wsh({ hash: decodeBech32.data }).output;
8386
}
8487
}
8588
}
86-
87-
throw new Error(address + ' has no matching Script')
88-
}
89-
90-
module.exports = {
91-
fromBase58Check: fromBase58Check,
92-
fromBech32: fromBech32,
93-
fromOutputScript: fromOutputScript,
94-
toBase58Check: toBase58Check,
95-
toBech32: toBech32,
96-
toOutputScript: toOutputScript
89+
throw new Error(address + ' has no matching Script');
9790
}
91+
exports.toOutputScript = toOutputScript;

0 commit comments

Comments
 (0)