Fix compiler errors, tests, and scripts

This commit is contained in:
junderw 2018-12-26 14:25:33 +09:00
parent e855bde3b3
commit d684a6b2ef
No known key found for this signature in database
GPG key ID: B256185D3A971908
60 changed files with 145 additions and 57 deletions

View file

@ -2,7 +2,7 @@
"name": "bitcoinjs-lib",
"version": "4.0.2",
"description": "Client-side Bitcoin JavaScript library",
"main": "./src/index.js",
"main": "./dist/src/index.js",
"engines": {
"node": ">=8.0.0"
},
@ -17,17 +17,18 @@
"coverage-report": "nyc report --reporter=lcov",
"coverage-html": "nyc report --reporter=html",
"coverage": "nyc --check-coverage --branches 90 --functions 90 mocha",
"integration": "mocha --timeout 50000 test/integration/",
"integration": "npm run build && mocha --timeout 50000 test/integration/",
"standard": "standard",
"test": "npm run standard && npm run coverage",
"unit": "mocha"
"test": "npm run build && npm run standard && npm run coverage",
"unit": "npm run build && mocha",
"build": "tsc -p tsconfig.json"
},
"repository": {
"type": "git",
"url": "https://github.com/bitcoinjs/bitcoinjs-lib.git"
},
"files": [
"src"
"dist/src"
],
"dependencies": {
"bech32": "^1.1.2",

View file

@ -95,3 +95,4 @@ module.exports = {
toBech32: toBech32,
toOutputScript: toOutputScript
}
export {}

View file

@ -175,3 +175,4 @@ Block.prototype.checkProofOfWork = function () {
}
module.exports = Block
export {}

View file

@ -27,3 +27,4 @@ module.exports = {
readUInt64LE: readUInt64LE,
writeUInt64LE: writeUInt64LE
}
export {}

View file

@ -68,3 +68,4 @@ module.exports = {
witness: classifyWitness,
types: types
}
export {}

View file

@ -27,3 +27,4 @@ module.exports = {
sha1: sha1,
sha256: sha256
}
export {}

View file

@ -104,3 +104,4 @@ module.exports = {
fromPublicKey,
fromWIF
}
export {}

View file

@ -14,3 +14,4 @@ module.exports = {
payments: require('./payments'),
script: script
}
export {}

View file

@ -36,3 +36,4 @@ module.exports = {
wif: 0xef
}
}
export {}

View file

@ -28,7 +28,10 @@ function p2data (a, opts) {
}, a)
const network = a.network || BITCOIN_NETWORK
const o = { network }
const o = {
network,
data: undefined
}
lazy.prop(o, 'output', function () {
if (!a.data) return
@ -54,3 +57,4 @@ function p2data (a, opts) {
}
module.exports = p2data
export {}

View file

@ -10,3 +10,4 @@ module.exports = { embed, p2ms, p2pk, p2pkh, p2sh, p2wpkh, p2wsh }
// TODO
// witness commitment
export {}

View file

@ -28,3 +28,4 @@ function value (f) {
}
module.exports = { prop, value }
export {}

View file

@ -42,7 +42,15 @@ function p2ms (a, opts) {
}, a)
const network = a.network || BITCOIN_NETWORK
const o = { network }
const o = {
network,
m: undefined,
n: undefined,
pubkeys: undefined,
output: undefined,
input: undefined,
signatures: undefined,
}
let chunks
let decoded = false
@ -129,7 +137,7 @@ function p2ms (a, opts) {
if (a.input[0] !== OPS.OP_0) throw new TypeError('Input is invalid')
if (o.signatures.length === 0 || !o.signatures.every(isAcceptableSignature)) throw new TypeError('Input has invalid signature(s)')
if (a.signatures && !stacksEqual(a.signatures.equals(o.signatures))) throw new TypeError('Signature mismatch')
if (a.signatures && !stacksEqual(a.signatures.equals(o.signatures), undefined)) throw new TypeError('Signature mismatch')
if (a.m !== undefined && a.m !== a.signatures.length) throw new TypeError('Signature count mismatch')
}
}
@ -138,3 +146,4 @@ function p2ms (a, opts) {
}
module.exports = p2ms
export {}

View file

@ -30,7 +30,12 @@ function p2pk (a, opts) {
const _chunks = lazy.value(function () { return bscript.decompile(a.input) })
const network = a.network || BITCOIN_NETWORK
const o = { network }
const o = {
network,
input: undefined,
pubkey: undefined,
signature: undefined,
}
lazy.prop(o, 'output', function () {
if (!a.pubkey) return
@ -78,3 +83,4 @@ function p2pk (a, opts) {
}
module.exports = p2pk
export {}

View file

@ -40,7 +40,12 @@ function p2pkh (a, opts) {
const _chunks = lazy.value(function () { return bscript.decompile(a.input) })
const network = a.network || BITCOIN_NETWORK
const o = { network }
const o = {
network,
hash: undefined,
pubkey: undefined,
input: undefined,
}
lazy.prop(o, 'address', function () {
if (!o.hash) return
@ -135,3 +140,4 @@ function p2pkh (a, opts) {
}
module.exports = p2pkh
export {}

View file

@ -50,7 +50,12 @@ function p2sh (a, opts) {
network = (a.redeem && a.redeem.network) || BITCOIN_NETWORK
}
const o = { network }
const o = {
network,
hash: undefined,
redeem: undefined,
input: undefined,
}
const _address = lazy.value(function () {
const payload = bs58check.decode(a.address)
@ -191,3 +196,4 @@ function p2sh (a, opts) {
}
module.exports = p2sh
export {}

View file

@ -46,7 +46,12 @@ function p2wpkh (a, opts) {
})
const network = a.network || BITCOIN_NETWORK
const o = { network }
const o = {
network,
hash: undefined,
pubkey: undefined,
witness: undefined,
}
lazy.prop(o, 'address', function () {
if (!o.hash) return
@ -133,3 +138,4 @@ function p2wpkh (a, opts) {
}
module.exports = p2wpkh
export {}

View file

@ -64,7 +64,12 @@ function p2wsh (a, opts) {
network = (a.redeem && a.redeem.network) || BITCOIN_NETWORK
}
const o = { network }
const o = {
network,
hash: undefined,
redeem: undefined,
witness: undefined,
}
lazy.prop(o, 'address', function () {
if (!o.hash) return
@ -178,3 +183,4 @@ function p2wsh (a, opts) {
}
module.exports = p2wsh
export {}

View file

@ -203,3 +203,4 @@ module.exports = {
isPushOnly: isPushOnly,
isDefinedHashType: isDefinedHashType
}
export {}

View file

@ -65,3 +65,4 @@ module.exports = {
decode: decode,
encode: encode
}
export {}

View file

@ -62,3 +62,4 @@ module.exports = {
decode: decode,
encode: encode
}
export {}

View file

@ -2,3 +2,4 @@ module.exports = {
input: require('./input'),
output: require('./output')
}
export {}

View file

@ -21,3 +21,4 @@ function check (script, allowIncomplete) {
check.toJSON = function () { return 'multisig input' }
module.exports = { check }
export {}

View file

@ -27,3 +27,4 @@ function check (script, allowIncomplete) {
check.toJSON = function () { return 'multi-sig output' }
module.exports = { check }
export {}

View file

@ -12,3 +12,4 @@ function check (script) {
check.toJSON = function () { return 'null data output' }
module.exports = { output: { check: check } }
export {}

View file

@ -2,3 +2,4 @@ module.exports = {
input: require('./input'),
output: require('./output')
}
export {}

View file

@ -13,3 +13,4 @@ check.toJSON = function () { return 'pubKey input' }
module.exports = {
check: check
}
export {}

View file

@ -13,3 +13,4 @@ function check (script) {
check.toJSON = function () { return 'pubKey output' }
module.exports = { check }
export {}

View file

@ -2,3 +2,4 @@ module.exports = {
input: require('./input'),
output: require('./output')
}
export {}

View file

@ -12,3 +12,4 @@ function check (script) {
check.toJSON = function () { return 'pubKeyHash input' }
module.exports = { check }
export {}

View file

@ -16,3 +16,4 @@ function check (script) {
check.toJSON = function () { return 'pubKeyHash output' }
module.exports = { check }
export {}

View file

@ -2,3 +2,4 @@ module.exports = {
input: require('./input'),
output: require('./output')
}
export {}

View file

@ -46,3 +46,4 @@ function check (script, allowIncomplete) {
check.toJSON = function () { return 'scriptHash input' }
module.exports = { check }
export {}

View file

@ -14,3 +14,4 @@ function check (script) {
check.toJSON = function () { return 'scriptHash output' }
module.exports = { check }
export {}

View file

@ -1,3 +1,4 @@
module.exports = {
output: require('./output')
}
export {}

View file

@ -40,3 +40,4 @@ module.exports = {
decode: decode,
encode: encode
}
export {}

View file

@ -2,3 +2,4 @@ module.exports = {
input: require('./input'),
output: require('./output')
}
export {}

View file

@ -16,3 +16,4 @@ function check (script) {
check.toJSON = function () { return 'witnessPubKeyHash input' }
module.exports = { check }
export {}

View file

@ -15,3 +15,4 @@ check.toJSON = function () { return 'Witness pubKeyHash output' }
module.exports = {
check
}
export {}

View file

@ -2,3 +2,4 @@ module.exports = {
input: require('./input'),
output: require('./output')
}
export {}

View file

@ -37,3 +37,4 @@ function check (chunks, allowIncomplete) {
check.toJSON = function () { return 'witnessScriptHash input' }
module.exports = { check }
export {}

View file

@ -13,3 +13,4 @@ function check (script) {
check.toJSON = function () { return 'Witness scriptHash output' }
module.exports = { check }
export {}

View file

@ -138,7 +138,7 @@ Transaction.fromBuffer = function (buffer, __noStrict) {
}
Transaction.fromHex = function (hex) {
return Transaction.fromBuffer(Buffer.from(hex, 'hex'))
return Transaction.fromBuffer(Buffer.from(hex, 'hex'), undefined)
}
Transaction.isCoinbaseHash = function (buffer) {
@ -490,3 +490,4 @@ Transaction.prototype.setWitness = function (index, witness) {
}
module.exports = Transaction
export {}

View file

@ -102,7 +102,7 @@ function expandInput (scriptSig, witnessStack, type, scriptPubKey) {
const outputType = classify.output(redeem.output)
let expanded
if (outputType === SCRIPT_TYPES.P2WPKH) {
expanded = expandInput(redeem.input, redeem.witness, outputType)
expanded = expandInput(redeem.input, redeem.witness, outputType, undefined)
} else {
expanded = expandInput(bscript.compile(redeem.witness), [], outputType, redeem.output)
}
@ -473,7 +473,7 @@ TransactionBuilder.prototype.setVersion = function (version) {
}
TransactionBuilder.fromTransaction = function (transaction, network) {
const txb = new TransactionBuilder(network)
const txb = new TransactionBuilder(network, undefined)
// Copy transaction fields
txb.setVersion(transaction.version)
@ -537,11 +537,17 @@ TransactionBuilder.prototype.__addInputUnsafe = function (txHash, vout, options)
const prevTxOut = txHash.toString('hex') + ':' + vout
if (this.__prevTxSet[prevTxOut] !== undefined) throw new Error('Duplicate TxOut: ' + prevTxOut)
let input = {}
let input = {
value: undefined,
prevOutScript: undefined,
pubkeys: undefined,
signatures: undefined,
prevOutType: undefined,
}
// derive what we can from the scriptSig
if (options.script !== undefined) {
input = expandInput(options.script, options.witness || [])
input = expandInput(options.script, options.witness || [], undefined, undefined)
}
// if an input value was given, retain it
@ -554,7 +560,7 @@ TransactionBuilder.prototype.__addInputUnsafe = function (txHash, vout, options)
let prevOutType
if (!input.pubkeys && !input.signatures) {
const expanded = expandOutput(options.prevOutScript)
const expanded = expandOutput(options.prevOutScript, undefined)
if (expanded.pubkeys) {
input.pubkeys = expanded.pubkeys
input.signatures = expanded.signatures
@ -705,10 +711,10 @@ function signatureHashType (buffer) {
}
TransactionBuilder.prototype.__canModifyInputs = function () {
return this.__inputs.every(function (input) {
return (this.__inputs || []).every(function (input) {
if (!input.signatures) return true
return input.signatures.every(function (signature) {
return (input.signatures || []).every(function (signature) {
if (!signature) return true
const hashType = signatureHashType(signature)
@ -775,3 +781,4 @@ TransactionBuilder.prototype.__overMaximumFees = function (bytes) {
}
module.exports = TransactionBuilder
export {}

View file

@ -47,3 +47,4 @@ for (var typeName in typeforce) {
}
module.exports = types
export {}

View file

@ -1,7 +1,7 @@
const { describe, it } = require('mocha')
const assert = require('assert')
const baddress = require('../src/address')
const bscript = require('../src/script')
const baddress = require('../dist/src/address')
const bscript = require('../dist/src/script')
const fixtures = require('./fixtures/address.json')
const NETWORKS = Object.assign({
litecoin: {
@ -14,7 +14,7 @@ const NETWORKS = Object.assign({
scriptHash: 0x32,
wif: 0xb0
}
}, require('../src/networks'))
}, require('../dist/src/networks'))
describe('address', function () {
describe('fromBase58Check', function () {

View file

@ -1,6 +1,6 @@
const { describe, it, beforeEach } = require('mocha')
const assert = require('assert')
const Block = require('../src/block')
const Block = require('../dist/src/block')
const fixtures = require('./fixtures/block')

View file

@ -1,6 +1,6 @@
const { describe, it } = require('mocha')
const assert = require('assert')
const bufferutils = require('../src/bufferutils')
const bufferutils = require('../dist/src/bufferutils')
const fixtures = require('./fixtures/bufferutils.json')

View file

@ -1,18 +1,18 @@
const { describe, it } = require('mocha')
const assert = require('assert')
const bscript = require('../src/script')
const classify = require('../src/classify')
const bscript = require('../dist/src/script')
const classify = require('../dist/src/classify')
const fixtures = require('./fixtures/templates.json')
const multisig = require('../src/templates/multisig')
const nullData = require('../src/templates/nulldata')
const pubKey = require('../src/templates/pubkey')
const pubKeyHash = require('../src/templates/pubkeyhash')
const scriptHash = require('../src/templates/scripthash')
const witnessPubKeyHash = require('../src/templates/witnesspubkeyhash')
const witnessScriptHash = require('../src/templates/witnessscripthash')
const witnessCommitment = require('../src/templates/witnesscommitment')
const multisig = require('../dist/src/templates/multisig')
const nullData = require('../dist/src/templates/nulldata')
const pubKey = require('../dist/src/templates/pubkey')
const pubKeyHash = require('../dist/src/templates/pubkeyhash')
const scriptHash = require('../dist/src/templates/scripthash')
const witnessPubKeyHash = require('../dist/src/templates/witnesspubkeyhash')
const witnessScriptHash = require('../dist/src/templates/witnessscripthash')
const witnessCommitment = require('../dist/src/templates/witnesscommitment')
const tmap = {
pubKey,

View file

@ -1,6 +1,6 @@
const { describe, it } = require('mocha')
const assert = require('assert')
const bcrypto = require('../src/crypto')
const bcrypto = require('../dist/src/crypto')
const fixtures = require('./fixtures/crypto')

View file

@ -5,12 +5,12 @@ const assert = require('assert')
const proxyquire = require('proxyquire')
const hoodwink = require('hoodwink')
const ECPair = require('../src/ecpair')
const ECPair = require('../dist/src/ecpair')
const tinysecp = require('tiny-secp256k1')
const fixtures = require('./fixtures/ecpair.json')
const NETWORKS = require('../src/networks')
const NETWORKS = require('../dist/src/networks')
const NETWORKS_LIST = [] // Object.values(NETWORKS)
for (let networkName in NETWORKS) {
NETWORKS_LIST.push(NETWORKS[networkName])
@ -144,7 +144,7 @@ describe('ECPair', function () {
describe('uses randombytes RNG', function () {
it('generates a ECPair', function () {
const stub = { randombytes: function () { return d } }
const ProxiedECPair = proxyquire('../src/ecpair', stub)
const ProxiedECPair = proxyquire('../dist/src/ecpair', stub)
const keyPair = ProxiedECPair.makeRandom()
assert.strictEqual(keyPair.toWIF(), exWIF)

View file

@ -4,7 +4,7 @@ const u = require('./payments.utils')
;['embed', 'p2ms', 'p2pk', 'p2pkh', 'p2sh', 'p2wpkh', 'p2wsh'].forEach(function (p) {
describe(p, function () {
const fn = require('../src/payments/' + p)
const fn = require('../dist/src/payments/' + p)
const fixtures = require('./fixtures/' + p)
fixtures.valid.forEach(function (f, i) {

View file

@ -1,6 +1,6 @@
const t = require('assert')
const bscript = require('../src/script')
const BNETWORKS = require('../src/networks')
const bscript = require('../dist/src/script')
const BNETWORKS = require('../dist/src/networks')
function tryHex (x) {
if (Buffer.isBuffer(x)) return x.toString('hex')

View file

@ -1,6 +1,6 @@
const { describe, it } = require('mocha')
const assert = require('assert')
const bscript = require('../src/script')
const bscript = require('../dist/src/script')
const minimalData = require('minimaldata')
const fixtures = require('./fixtures/script.json')

View file

@ -1,6 +1,6 @@
const { describe, it } = require('mocha')
const assert = require('assert')
const scriptNumber = require('../src/script_number')
const scriptNumber = require('../dist/src/script_number')
const fixtures = require('./fixtures/script_number.json')
describe('script-number', function () {

View file

@ -1,6 +1,6 @@
const { describe, it } = require('mocha')
const assert = require('assert')
const bscriptSig = require('../src/script').signature
const bscriptSig = require('../dist/src/script').signature
const Buffer = require('safe-buffer').Buffer
const fixtures = require('./fixtures/signature.json')

View file

@ -1,8 +1,8 @@
const { describe, it, beforeEach } = require('mocha')
const assert = require('assert')
const bscript = require('../src/script')
const bscript = require('../dist/src/script')
const fixtures = require('./fixtures/transaction')
const Transaction = require('../src/transaction')
const Transaction = require('../dist/src/transaction')
describe('Transaction', function () {
function fromRaw (raw, noWitness) {

View file

@ -1,13 +1,13 @@
const { describe, it, beforeEach } = require('mocha')
const assert = require('assert')
const baddress = require('../src/address')
const bscript = require('../src/script')
const payments = require('../src/payments')
const baddress = require('../dist/src/address')
const bscript = require('../dist/src/script')
const payments = require('../dist/src/payments')
const ECPair = require('../src/ecpair')
const Transaction = require('../src/transaction')
const TransactionBuilder = require('../src/transaction_builder')
const NETWORKS = require('../src/networks')
const ECPair = require('../dist/src/ecpair')
const Transaction = require('../dist/src/transaction')
const TransactionBuilder = require('../dist/src/transaction_builder')
const NETWORKS = require('../dist/src/networks')
const fixtures = require('./fixtures/transaction_builder')

View file

@ -1,6 +1,6 @@
const { describe, it } = require('mocha')
const assert = require('assert')
const types = require('../src/types')
const types = require('../dist/src/types')
const typeforce = require('typeforce')
describe('types', function () {

View file

@ -22,6 +22,7 @@
"src/**/*"
],
"exclude": [
"**/*.spec.ts"
"**/*.spec.ts",
"node_modules/**/*"
]
}