Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16195cc6ce |
@ -32,7 +32,7 @@ __removed__
|
|||||||
- Removed `bufferutils` (#1035)
|
- Removed `bufferutils` (#1035)
|
||||||
- Removed `networks.litecoin`, BYO non-Bitcoin networks instead (#1095)
|
- Removed `networks.litecoin`, BYO non-Bitcoin networks instead (#1095)
|
||||||
- Removed `script.isCanonicalSignature`, use `script.isCanonicalScriptSignature` instead (#1094)
|
- Removed `script.isCanonicalSignature`, use `script.isCanonicalScriptSignature` instead (#1094)
|
||||||
- Removed `script.*.input/output/check` functions (`templates`), use `payments.*` instead (`templates` previously added in #681, #682) (#1119)
|
- Removed `script.*.input/output/check` functions (`templates`) (previously added in #681, #682) (#1119)
|
||||||
- Removed dependency `bigi`, uses `bn.js` internally now (via `tiny-secp256k1`) (#1070, #1112)
|
- 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)
|
- Removed public access to `ECPair` constructor, use exported functions `ECPair.fromPrivateKey`, `ECPair.fromWIF`, `ECPair.makeRandom`, or `ECPair.fromPublicKey` (#1070)
|
||||||
|
|
||||||
|
|||||||
@ -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.
|
- Friendly, with a strong and helpful community, ready to answer questions.
|
||||||
|
|
||||||
## Documentation
|
## 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
|
## Installation
|
||||||
|
|||||||
@ -5,6 +5,9 @@ const types = require('./types')
|
|||||||
const wif = require('wif')
|
const wif = require('wif')
|
||||||
|
|
||||||
const NETWORKS = require('./networks')
|
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({
|
const isOptions = typeforce.maybe(typeforce.compile({
|
||||||
compressed: types.maybe(types.Boolean),
|
compressed: types.maybe(types.Boolean),
|
||||||
network: types.maybe(types.Network)
|
network: types.maybe(types.Network)
|
||||||
@ -54,7 +57,7 @@ function fromPrivateKey (buffer, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fromPublicKey (buffer, options) {
|
function fromPublicKey (buffer, options) {
|
||||||
typeforce(ecc.isPoint, buffer)
|
typeforce(isPoint, buffer)
|
||||||
typeforce(isOptions, options)
|
typeforce(isOptions, options)
|
||||||
return new ECPair(null, buffer, options)
|
return new ECPair(null, buffer, options)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it */
|
const { describe, it } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const baddress = require('../src/address')
|
const baddress = require('../src/address')
|
||||||
const bscript = require('../src/script')
|
const bscript = require('../src/script')
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it */
|
const { describe, it } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const base58 = require('bs58')
|
const base58 = require('bs58')
|
||||||
const bitcoin = require('../')
|
const bitcoin = require('../')
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it, beforeEach */
|
const { describe, it, beforeEach } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const Block = require('../src/block')
|
const Block = require('../src/block')
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it */
|
const { describe, it } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const bufferutils = require('../src/bufferutils')
|
const bufferutils = require('../src/bufferutils')
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it */
|
const { describe, it } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const bscript = require('../src/script')
|
const bscript = require('../src/script')
|
||||||
const classify = require('../src/classify')
|
const classify = require('../src/classify')
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it */
|
const { describe, it } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const bcrypto = require('../src/crypto')
|
const bcrypto = require('../src/crypto')
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* global describe, it, beforeEach */
|
|
||||||
/* eslint-disable no-new */
|
/* eslint-disable no-new */
|
||||||
|
|
||||||
|
const { describe, it, beforeEach } = require('mocha')
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const proxyquire = require('proxyquire')
|
const proxyquire = require('proxyquire')
|
||||||
const hoodwink = require('hoodwink')
|
const hoodwink = require('hoodwink')
|
||||||
@ -22,23 +22,7 @@ const GROUP_ORDER = Buffer.from('fffffffffffffffffffffffffffffffebaaedce6af48a03
|
|||||||
const GROUP_ORDER_LESS_1 = Buffer.from('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140', 'hex')
|
const GROUP_ORDER_LESS_1 = Buffer.from('fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140', 'hex')
|
||||||
|
|
||||||
describe('ECPair', function () {
|
describe('ECPair', function () {
|
||||||
describe('getPublicKey', function () {
|
describe('constructor', 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 () {
|
it('defaults to compressed', function () {
|
||||||
const keyPair = ECPair.fromPrivateKey(ONE)
|
const keyPair = ECPair.fromPrivateKey(ONE)
|
||||||
|
|
||||||
@ -65,6 +49,8 @@ describe('ECPair', function () {
|
|||||||
fixtures.valid.forEach(function (f) {
|
fixtures.valid.forEach(function (f) {
|
||||||
it('derives public key for ' + f.WIF, function () {
|
it('derives public key for ' + f.WIF, function () {
|
||||||
const d = Buffer.from(f.d, 'hex')
|
const d = Buffer.from(f.d, 'hex')
|
||||||
|
console.log(d)
|
||||||
|
|
||||||
const keyPair = ECPair.fromPrivateKey(d, {
|
const keyPair = ECPair.fromPrivateKey(d, {
|
||||||
compressed: f.compressed
|
compressed: f.compressed
|
||||||
})
|
})
|
||||||
@ -73,25 +59,37 @@ describe('ECPair', function () {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
fixtures.invalid.fromPrivateKey.forEach(function (f) {
|
fixtures.invalid.constructor.forEach(function (f) {
|
||||||
it('throws ' + f.exception, function () {
|
it('throws ' + f.exception, function () {
|
||||||
const d = Buffer.from(f.d, 'hex')
|
if (f.d) {
|
||||||
assert.throws(function () {
|
const d = Buffer.from(f.d, 'hex')
|
||||||
ECPair.fromPrivateKey(d, f.options)
|
assert.throws(function () {
|
||||||
}, new RegExp(f.exception))
|
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))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('fromPublicKey', function () {
|
describe('getPublicKey', function () {
|
||||||
fixtures.invalid.fromPublicKey.forEach(function (f) {
|
let keyPair
|
||||||
it('throws ' + f.exception, function () {
|
|
||||||
const Q = Buffer.from(f.Q, 'hex')
|
beforeEach(function () {
|
||||||
assert.throws(function () {
|
keyPair = ECPair.fromPrivateKey(ONE)
|
||||||
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 () {
|
describe('fromWIF', function () {
|
||||||
|
|||||||
23
test/fixtures/ecpair.json
vendored
23
test/fixtures/ecpair.json
vendored
@ -66,7 +66,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"invalid": {
|
"invalid": {
|
||||||
"fromPrivateKey": [
|
"constructor": [
|
||||||
{
|
{
|
||||||
"exception": "Private key not in range \\[1, n\\)",
|
"exception": "Private key not in range \\[1, n\\)",
|
||||||
"d": "0000000000000000000000000000000000000000000000000000000000000000"
|
"d": "0000000000000000000000000000000000000000000000000000000000000000"
|
||||||
@ -93,26 +93,7 @@
|
|||||||
"network": {}
|
"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": [
|
"fromWIF": [
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it */
|
const { describe, it } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const bitcoin = require('../../')
|
const bitcoin = require('../../')
|
||||||
const dhttp = require('dhttp/200')
|
const dhttp = require('dhttp/200')
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it */
|
const { describe, it } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const bip32 = require('bip32')
|
const bip32 = require('bip32')
|
||||||
const bip39 = require('bip39')
|
const bip39 = require('bip39')
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* global describe, it */
|
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
const { describe, it } = require('mocha')
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const bitcoin = require('../../')
|
const bitcoin = require('../../')
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it, before */
|
const { describe, it, before } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const bitcoin = require('../../')
|
const bitcoin = require('../../')
|
||||||
const regtestUtils = require('./_regtest')
|
const regtestUtils = require('./_regtest')
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it */
|
const { describe, it } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const BN = require('bn.js')
|
const BN = require('bn.js')
|
||||||
const bitcoin = require('../../')
|
const bitcoin = require('../../')
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it, before */
|
const { describe, it, before } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const bitcoin = require('../../')
|
const bitcoin = require('../../')
|
||||||
const regtestUtils = require('./_regtest')
|
const regtestUtils = require('./_regtest')
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
/* global describe, it */
|
|
||||||
|
|
||||||
const bitcoin = require('../../')
|
const bitcoin = require('../../')
|
||||||
|
|
||||||
|
const { describe, it } = require('mocha')
|
||||||
const regtestUtils = require('./_regtest')
|
const regtestUtils = require('./_regtest')
|
||||||
const NETWORK = regtestUtils.network
|
const NETWORK = regtestUtils.network
|
||||||
const keyPairs = [
|
const keyPairs = [
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it */
|
const { describe, it } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const bitcoin = require('../../')
|
const bitcoin = require('../../')
|
||||||
const ecc = require('tiny-secp256k1')
|
const ecc = require('tiny-secp256k1')
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it */
|
const { describe, it } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const bitcoin = require('../../')
|
const bitcoin = require('../../')
|
||||||
const regtestUtils = require('./_regtest')
|
const regtestUtils = require('./_regtest')
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it */
|
const { describe, it } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const u = require('./payments.utils')
|
const u = require('./payments.utils')
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
let t = require('assert')
|
const t = require('assert')
|
||||||
let bscript = require('../src/script')
|
const bscript = require('../src/script')
|
||||||
let bnetworks = require('../src/networks')
|
const bnetworks = require('../src/networks')
|
||||||
|
|
||||||
function tryHex (x) {
|
function tryHex (x) {
|
||||||
if (Buffer.isBuffer(x)) return x.toString('hex')
|
if (Buffer.isBuffer(x)) return x.toString('hex')
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it */
|
const { describe, it } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const bscript = require('../src/script')
|
const bscript = require('../src/script')
|
||||||
const minimalData = require('minimaldata')
|
const minimalData = require('minimaldata')
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it */
|
const { describe, it } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const scriptNumber = require('../src/script_number')
|
const scriptNumber = require('../src/script_number')
|
||||||
const fixtures = require('./fixtures/script_number.json')
|
const fixtures = require('./fixtures/script_number.json')
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it */
|
const { describe, it } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const bscriptSig = require('../src/script').signature
|
const bscriptSig = require('../src/script').signature
|
||||||
const Buffer = require('safe-buffer').Buffer
|
const Buffer = require('safe-buffer').Buffer
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it, beforeEach */
|
const { describe, it, beforeEach } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const bscript = require('../src/script')
|
const bscript = require('../src/script')
|
||||||
const fixtures = require('./fixtures/transaction')
|
const fixtures = require('./fixtures/transaction')
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it, beforeEach */
|
const { describe, it, beforeEach } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const baddress = require('../src/address')
|
const baddress = require('../src/address')
|
||||||
const bcrypto = require('../src/crypto')
|
const bcrypto = require('../src/crypto')
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* global describe, it */
|
const { describe, it } = require('mocha')
|
||||||
|
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const types = require('../src/types')
|
const types = require('../src/types')
|
||||||
const typeforce = require('typeforce')
|
const typeforce = require('typeforce')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user