Skip to content

Commit 3c4f7c3

Browse files
Updated installation & usage instructions in README.md.
Renamed library to rn-bitcoinjs-lib & updated repository url in package.json. Added tests from bitcoinjs-lib.
1 parent ce1ba98 commit 3c4f7c3

Some content is hidden

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

55 files changed

+12379
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Estimated to be in use by over 15 million wallet users and is the backbone for a
2424

2525
## Installation
2626
``` bash
27-
yarn add https://github.com/coreyphillips/react-native-bitcoinjs-lib
27+
yarn add rn-bitcoinjs-lib
2828
```
2929

3030
## Setup
@@ -69,7 +69,7 @@ require('crypto')
6969
**Usage**
7070
``` javascript
7171
import "./shim";
72-
const bitcoin = require("bitcoinjs-lib");
72+
const bitcoin = require("rn-bitcoinjs-lib");
7373
const keyPair = bitcoin.ECPair.makeRandom();
7474
const { address } = bitcoin.payments.p2pkh({ pubkey: keyPair.publicKey });
7575
console.log(address);

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "bitcoinjs-lib",
3-
"version": "4.0.1",
2+
"name": "rn-bitcoinjs-lib",
3+
"version": "4.0.1-3",
44
"description": "Client-side Bitcoin JavaScript library",
55
"main": "./src/index.js",
66
"engines": {
@@ -24,7 +24,7 @@
2424
},
2525
"repository": {
2626
"type": "git",
27-
"url": "https://github.com/bitcoinjs/bitcoinjs-lib.git"
27+
"url": "https://github.com/coreyphillips/rn-bitcoinjs-lib.git"
2828
},
2929
"files": [
3030
"src"
@@ -39,7 +39,7 @@
3939
"create-hmac": "^1.1.3",
4040
"merkle-lib": "^2.0.10",
4141
"pushdata-bitcoin": "^1.0.1",
42-
"randombytes": "^2.0.1",
42+
"react-native-randombytes": "^3.0.0",
4343
"safe-buffer": "^5.1.1",
4444
"tiny-secp256k1": "^1.0.0",
4545
"typeforce": "^1.11.3",

test/address.js

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/* global describe, it */
2+
3+
const assert = require('assert')
4+
const baddress = require('../src/address')
5+
const bscript = require('../src/script')
6+
const fixtures = require('./fixtures/address.json')
7+
const NETWORKS = Object.assign({
8+
litecoin: {
9+
messagePrefix: '\x19Litecoin Signed Message:\n',
10+
bip32: {
11+
public: 0x019da462,
12+
private: 0x019d9cfe
13+
},
14+
pubKeyHash: 0x30,
15+
scriptHash: 0x32,
16+
wif: 0xb0
17+
}
18+
}, require('../src/networks'))
19+
20+
describe('address', function () {
21+
describe('fromBase58Check', function () {
22+
fixtures.standard.forEach(function (f) {
23+
if (!f.base58check) return
24+
25+
it('decodes ' + f.base58check, function () {
26+
const decode = baddress.fromBase58Check(f.base58check)
27+
28+
assert.strictEqual(decode.version, f.version)
29+
assert.strictEqual(decode.hash.toString('hex'), f.hash)
30+
})
31+
})
32+
33+
fixtures.invalid.fromBase58Check.forEach(function (f) {
34+
it('throws on ' + f.exception, function () {
35+
assert.throws(function () {
36+
baddress.fromBase58Check(f.address)
37+
}, new RegExp(f.address + ' ' + f.exception))
38+
})
39+
})
40+
})
41+
42+
describe('fromBech32', function () {
43+
fixtures.standard.forEach((f) => {
44+
if (!f.bech32) return
45+
46+
it('decodes ' + f.bech32, function () {
47+
const actual = baddress.fromBech32(f.bech32)
48+
49+
assert.strictEqual(actual.version, f.version)
50+
assert.strictEqual(actual.prefix, NETWORKS[f.network].bech32)
51+
assert.strictEqual(actual.data.toString('hex'), f.data)
52+
})
53+
})
54+
55+
fixtures.invalid.bech32.forEach((f, i) => {
56+
it('decode fails for ' + f.bech32 + '(' + f.exception + ')', function () {
57+
assert.throws(function () {
58+
baddress.fromBech32(f.address)
59+
}, new RegExp(f.exception))
60+
})
61+
})
62+
})
63+
64+
describe('fromOutputScript', function () {
65+
fixtures.standard.forEach(function (f) {
66+
it('encodes ' + f.script.slice(0, 30) + '... (' + f.network + ')', function () {
67+
const script = bscript.fromASM(f.script)
68+
const address = baddress.fromOutputScript(script, NETWORKS[f.network])
69+
70+
assert.strictEqual(address, f.base58check || f.bech32.toLowerCase())
71+
})
72+
})
73+
74+
fixtures.invalid.fromOutputScript.forEach(function (f) {
75+
it('throws when ' + f.script.slice(0, 30) + '... ' + f.exception, function () {
76+
const script = bscript.fromASM(f.script)
77+
78+
assert.throws(function () {
79+
baddress.fromOutputScript(script)
80+
}, new RegExp(f.exception))
81+
})
82+
})
83+
})
84+
85+
describe('toBase58Check', function () {
86+
fixtures.standard.forEach(function (f) {
87+
if (!f.base58check) return
88+
89+
it('encodes ' + f.hash + ' (' + f.network + ')', function () {
90+
const address = baddress.toBase58Check(Buffer.from(f.hash, 'hex'), f.version)
91+
92+
assert.strictEqual(address, f.base58check)
93+
})
94+
})
95+
})
96+
97+
describe('toBech32', function () {
98+
fixtures.bech32.forEach((f, i) => {
99+
if (!f.bech32) return
100+
const data = Buffer.from(f.data, 'hex')
101+
102+
it('encode ' + f.address, function () {
103+
assert.deepEqual(baddress.toBech32(data, f.version, f.prefix), f.address)
104+
})
105+
})
106+
107+
fixtures.invalid.bech32.forEach((f, i) => {
108+
if (!f.prefix || f.version === undefined || f.data === undefined) return
109+
110+
it('encode fails (' + f.exception, function () {
111+
assert.throws(function () {
112+
baddress.toBech32(Buffer.from(f.data, 'hex'), f.version, f.prefix)
113+
}, new RegExp(f.exception))
114+
})
115+
})
116+
})
117+
118+
describe('toOutputScript', function () {
119+
fixtures.standard.forEach(function (f) {
120+
it('decodes ' + f.script.slice(0, 30) + '... (' + f.network + ')', function () {
121+
const script = baddress.toOutputScript(f.base58check || f.bech32, NETWORKS[f.network])
122+
123+
assert.strictEqual(bscript.toASM(script), f.script)
124+
})
125+
})
126+
127+
fixtures.invalid.toOutputScript.forEach(function (f) {
128+
it('throws when ' + f.exception, function () {
129+
assert.throws(function () {
130+
baddress.toOutputScript(f.address, f.network)
131+
}, new RegExp(f.address + ' ' + f.exception))
132+
})
133+
})
134+
})
135+
})

0 commit comments

Comments
 (0)