Compare commits

...

9 Commits

Author SHA1 Message Date
Daniel Cousens
fbaad04f24
Merge pull request #1165 from fybwid/patch-1
Update README.md
2018-08-08 13:30:17 +10:00
Yosef Benny Widyokarsono
64b9646870
Update README.md
Fix example anchor at Documentation
2018-08-08 10:53:20 +08:00
Jonathan Underwood
e672875394
Merge pull request #1160 from bitcoinjs/notealt
CHANGELOG: note alternative to templates
2018-08-07 10:54:10 +09:00
Daniel Cousens
e639914d22
CHANGELOG: note alternative to templates 2018-08-03 10:34:49 +10:00
Jonathan Underwood
836f2b4263
Merge pull request #1146 from bitcoinjs/ectests
tests/ECPair: test fromPublic/fromPrivate in isolation
2018-08-01 11:47:05 +09:00
Daniel Cousens
85b1b92b6d tests/ECPair: test fromPublic/fromPrivate in isolation 2018-07-26 18:05:39 +10:00
Jonathan Underwood
d8b66641b3
Merge pull request #1139 from bitcoinjs/deps
4.0.1 | bump dependencies to 1.0.0 versions (and simplify Travis)
2018-07-23 17:30:00 +09:00
Daniel Cousens
3bb3b9f397 4.0.1 2018-07-23 17:07:42 +10:00
Daniel Cousens
29fc067696 CHANGELOG: add 4.0.1 2018-07-23 17:07:42 +10:00
6 changed files with 60 additions and 37 deletions

View File

@ -1,3 +1,8 @@
# 4.0.1
__fixed__
- Fixed `tiny-secp256k1` dependency version (used `ecurve`) (#1139)
- Fixed `TransactionBuilder` throwing when trying to sign `P2WSH(P2WPKH)` (#1135)
# 4.0.0
__added__
- Added [`bip32`](https://github.com/bitcoinjs/bip32) dependency as a primary export (#1073)
@ -27,7 +32,7 @@ __removed__
- Removed `bufferutils` (#1035)
- Removed `networks.litecoin`, BYO non-Bitcoin networks instead (#1095)
- Removed `script.isCanonicalSignature`, use `script.isCanonicalScriptSignature` instead (#1094)
- Removed `script.*.input/output/check` functions (`templates`) (previously added in #681, #682) (#1119)
- Removed `script.*.input/output/check` functions (`templates`), use `payments.*` instead (`templates` previously added in #681, #682) (#1119)
- Removed dependency `bigi`, uses `bn.js` internally now (via `tiny-secp256k1`) (#1070, #1112)
- Removed public access to `ECPair` constructor, use exported functions `ECPair.fromPrivateKey`, `ECPair.fromWIF`, `ECPair.makeRandom`, or `ECPair.fromPublicKey` (#1070)

View File

@ -27,7 +27,7 @@ Mistakes and bugs happen, but with your help in resolving and reporting [issues]
- Friendly, with a strong and helpful community, ready to answer questions.
## Documentation
Presently, we do not have any formal documentation other than our [examples](#Examples), please [ask for help](https://github.com/bitcoinjs/bitcoinjs-lib/issues/new) if our examples aren't enough to guide you.
Presently, we do not have any formal documentation other than our [examples](#examples), please [ask for help](https://github.com/bitcoinjs/bitcoinjs-lib/issues/new) if our examples aren't enough to guide you.
## Installation

View File

@ -1,6 +1,6 @@
{
"name": "bitcoinjs-lib",
"version": "4.0.0",
"version": "4.0.1",
"description": "Client-side Bitcoin JavaScript library",
"main": "./src/index.js",
"engines": {

View File

@ -5,9 +5,6 @@ const types = require('./types')
const wif = require('wif')
const NETWORKS = require('./networks')
// TODO: why is the function name toJSON weird?
function isPoint (x) { return ecc.isPoint(x) }
const isOptions = typeforce.maybe(typeforce.compile({
compressed: types.maybe(types.Boolean),
network: types.maybe(types.Network)
@ -57,7 +54,7 @@ function fromPrivateKey (buffer, options) {
}
function fromPublicKey (buffer, options) {
typeforce(isPoint, buffer)
typeforce(ecc.isPoint, buffer)
typeforce(isOptions, options)
return new ECPair(null, buffer, options)
}

View File

@ -22,7 +22,23 @@ const GROUP_ORDER = Buffer.from('fffffffffffffffffffffffffffffffebaaedce6af48a03
const GROUP_ORDER_LESS_1 = Buffer.from('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140', 'hex')
describe('ECPair', function () {
describe('constructor', function () {
describe('getPublicKey', function () {
let keyPair
beforeEach(function () {
keyPair = ECPair.fromPrivateKey(ONE)
})
it('calls pointFromScalar lazily', hoodwink(function () {
assert.strictEqual(keyPair.__Q, null)
// .publicKey forces the memoization
assert.strictEqual(keyPair.publicKey.toString('hex'), '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798')
assert.strictEqual(keyPair.__Q.toString('hex'), '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798')
}))
})
describe('fromPrivateKey', function () {
it('defaults to compressed', function () {
const keyPair = ECPair.fromPrivateKey(ONE)
@ -49,8 +65,6 @@ describe('ECPair', function () {
fixtures.valid.forEach(function (f) {
it('derives public key for ' + f.WIF, function () {
const d = Buffer.from(f.d, 'hex')
console.log(d)
const keyPair = ECPair.fromPrivateKey(d, {
compressed: f.compressed
})
@ -59,37 +73,25 @@ describe('ECPair', function () {
})
})
fixtures.invalid.constructor.forEach(function (f) {
fixtures.invalid.fromPrivateKey.forEach(function (f) {
it('throws ' + f.exception, function () {
if (f.d) {
const d = Buffer.from(f.d, 'hex')
assert.throws(function () {
ECPair.fromPrivateKey(d, f.options)
}, new RegExp(f.exception))
} else {
const Q = Buffer.from(f.Q, 'hex')
assert.throws(function () {
ECPair.fromPublicKey(Q, f.options)
}, new RegExp(f.exception))
}
const d = Buffer.from(f.d, 'hex')
assert.throws(function () {
ECPair.fromPrivateKey(d, f.options)
}, new RegExp(f.exception))
})
})
})
describe('getPublicKey', function () {
let keyPair
beforeEach(function () {
keyPair = ECPair.fromPrivateKey(ONE)
describe('fromPublicKey', function () {
fixtures.invalid.fromPublicKey.forEach(function (f) {
it('throws ' + f.exception, function () {
const Q = Buffer.from(f.Q, 'hex')
assert.throws(function () {
ECPair.fromPublicKey(Q, f.options)
}, new RegExp(f.exception))
})
})
it('calls pointFromScalar lazily', hoodwink(function () {
assert.strictEqual(keyPair.__Q, null)
// .publicKey forces the memoization
assert.strictEqual(keyPair.publicKey.toString('hex'), '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798')
assert.strictEqual(keyPair.__Q.toString('hex'), '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798')
}))
})
describe('fromWIF', function () {

View File

@ -66,7 +66,7 @@
}
],
"invalid": {
"constructor": [
"fromPrivateKey": [
{
"exception": "Private key not in range \\[1, n\\)",
"d": "0000000000000000000000000000000000000000000000000000000000000000"
@ -93,7 +93,26 @@
"network": {}
}
}
],
"fromPublicKey": [
{
"exception": "Expected isPoint, got Buffer",
"Q": "",
"options": {}
},
{
"exception": "Expected property \"network.messagePrefix\" of type Buffer|String, got undefined",
"Q": "044289801366bcee6172b771cf5a7f13aaecd237a0b9a1ff9d769cabc2e6b70a34cec320a0565fb7caf11b1ca2f445f9b7b012dda5718b3cface369ee3a034ded6",
"options": {
"network": {}
}
},
{
"description": "Bad X coordinate (== P)",
"exception": "Expected isPoint, got Buffer",
"Q": "040000000000000000000000000000000000000000000000000000000000000001fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
"options": {}
}
],
"fromWIF": [
{