noImplicitAny is now true

This commit is contained in:
junderw 2018-12-29 00:53:54 +09:00
parent 867f4b59f9
commit 4cddc83016
No known key found for this signature in database
GPG key ID: B256185D3A971908
14 changed files with 56 additions and 54 deletions

View file

@ -16,7 +16,7 @@
"scripts": {
"coverage-report": "nyc report --reporter=lcov",
"coverage-html": "nyc report --reporter=html",
"coverage": "nyc --check-coverage --branches 80 --functions 80 mocha",
"coverage": "nyc --check-coverage --branches 80 --functions 80 --lines 80 mocha",
"integration": "npm run build && mocha --timeout 50000 test/integration/",
"standard": "standard",
"test": "npm run build && npm run standard && npm run coverage",

View file

@ -1,13 +1,13 @@
import * as Networks from './networks'
import { Network } from './networks'
import * as types from './types'
const Buffer = require('safe-buffer').Buffer
const bech32 = require('bech32')
const bs58check = require('bs58check')
const bscript = require('./script')
const networks = require('./networks')
const typeforce = require('typeforce')
const types = require('./types')
const payments = require('./payments')
import * as Networks from './networks'
import { Network } from './networks'
export type Base58CheckResult = {
hash: Buffer;

View file

@ -1,9 +1,9 @@
import { Transaction } from './transaction'
import * as types from './types'
const Buffer = require('safe-buffer').Buffer
const bcrypto = require('./crypto')
const fastMerkleRoot = require('merkle-lib/fastRoot')
const typeforce = require('typeforce')
const types = require('./types')
const varuint = require('varuint-bitcoin')
const errorMerkleNoTxes = new TypeError('Cannot compute merkle root for zero transactions')

View file

@ -1,9 +1,9 @@
import { Network } from './networks'
import * as NETWORKS from './networks'
import * as types from './types'
const ecc = require('tiny-secp256k1')
const randomBytes = require('randombytes')
const typeforce = require('typeforce')
const types = require('./types')
const wif = require('wif')
const isOptions = typeforce.maybe(typeforce.compile({
@ -14,7 +14,7 @@ const isOptions = typeforce.maybe(typeforce.compile({
interface ECPairOptions {
compressed?: boolean
network?: Network
rng?(Buffer): Buffer
rng?(arg0: Buffer): Buffer
}
export interface ECPairInterface {
@ -75,19 +75,19 @@ function fromPrivateKey (buffer: Buffer, options: ECPairOptions): ECPair {
return new ECPair(buffer, null, options)
}
function fromPublicKey (buffer, options): ECPair {
function fromPublicKey (buffer: Buffer, options: ECPairOptions): ECPair {
typeforce(ecc.isPoint, buffer)
typeforce(isOptions, options)
return new ECPair(null, buffer, options)
}
function fromWIF (string, network): ECPair {
function fromWIF (string: string, network: Network | Array<Network>): ECPair {
const decoded = wif.decode(string)
const version = decoded.version
// list of networks?
if (types.Array(network)) {
network = network.filter(function (x) {
network = (<Array<Network>>network).filter(function (x: Network) {
return version === x.wif
}).pop()
@ -97,12 +97,12 @@ function fromWIF (string, network): ECPair {
} else {
network = network || NETWORKS.bitcoin
if (version !== network.wif) throw new Error('Invalid network version')
if (version !== (<Network>network).wif) throw new Error('Invalid network version')
}
return fromPrivateKey(decoded.privateKey, {
compressed: decoded.compressed,
network: network
network: <Network>network
})
}

View file

@ -1,11 +1,11 @@
const opcodes = require('bitcoin-ops')
const bip32 = require('bip32')
import { Block } from './block'
import * as ECPair from './ecpair'
import { Transaction } from './transaction'
import { TransactionBuilder } from './transaction_builder'
import * as address from './address'
import * as bip32 from 'bip32'
import * as crypto from './crypto'
import * as networks from './networks'
import * as payments from './payments'

View file

@ -41,12 +41,7 @@ export function p2pkh (a: Payment, opts: PaymentOpts): Payment {
const _chunks = lazy.value(function () { return bscript.decompile(a.input) })
const network = a.network || BITCOIN_NETWORK
const o = {
network,
hash: undefined,
pubkey: undefined,
input: undefined,
}
const o: Payment = { network }
lazy.prop(o, 'address', function () {
if (!o.hash) return

View file

@ -51,12 +51,7 @@ export function p2sh (a: Payment, opts: PaymentOpts): Payment {
network = (a.redeem && a.redeem.network) || BITCOIN_NETWORK
}
const o = {
network,
hash: undefined,
redeem: undefined,
input: undefined,
}
const o: Payment = { network }
const _address = lazy.value(function () {
const payload = bs58check.decode(a.address)

View file

@ -1,9 +1,9 @@
import * as types from './types'
const Buffer = require('safe-buffer').Buffer
const bip66 = require('bip66')
const ecc = require('tiny-secp256k1')
const pushdata = require('pushdata-bitcoin')
const typeforce = require('typeforce')
const types = require('./types')
const scriptNumber = require('./script_number')
const OPS = require('bitcoin-ops')
@ -100,7 +100,7 @@ export function decompile (buffer: Buffer | Array<number | Buffer>): Array<numbe
typeforce(types.Buffer, buffer)
const chunks = []
const chunks: Array<number | Buffer> = []
let i = 0
while (i < buffer.length) {
@ -123,7 +123,7 @@ export function decompile (buffer: Buffer | Array<number | Buffer>): Array<numbe
// decompile minimally
const op = asMinimalOP(data)
if (op !== undefined) {
chunks.push(op)
chunks.push(<number>op)
} else {
chunks.push(data)
}

View file

@ -32,7 +32,7 @@ export function decode (buffer: Buffer, maxLength?: number, minimal?: boolean):
return result
}
function scriptNumSize (i) {
function scriptNumSize (i: number): number {
return i > 0x7fffffff ? 5
: i > 0x7fffff ? 4
: i > 0x7fff ? 3

View file

@ -1,7 +1,7 @@
import * as types from './types'
const bip66 = require('bip66')
const Buffer = require('safe-buffer').Buffer
const typeforce = require('typeforce')
const types = require('./types')
const ZERO = Buffer.alloc(1, 0)
function toDER (x: Buffer): Buffer {

View file

@ -1,10 +1,10 @@
import * as bcrypto from './crypto'
import * as bscript from './script'
import * as types from './types'
const Buffer = require('safe-buffer').Buffer
const bscript = require('./script')
const bufferutils = require('./bufferutils')
const opcodes = require('bitcoin-ops')
const typeforce = require('typeforce')
const types = require('./types')
const varuint = require('varuint-bitcoin')
function varSliceSize (someScript: Buffer): number {
@ -73,7 +73,7 @@ export class Transaction {
this.ins = []
this.outs = []
}
static fromBuffer (buffer: Buffer, __noStrict: boolean): Transaction {
let offset: number = 0
@ -294,7 +294,7 @@ export class Transaction {
// ignore OP_CODESEPARATOR
const ourScript = bscript.compile(bscript.decompile(prevOutScript).filter((x) => {
return x !== opcodes.OP_CODESEPARATOR
return x !== <number>opcodes.OP_CODESEPARATOR
}))
const txTmp = this.clone()
@ -465,46 +465,46 @@ export class Transaction {
return Buffer.from(this.getHash(false).reverse()).toString('hex')
}
toBuffer (buffer: Buffer | void, initialOffset: number | void): Buffer {
toBuffer (buffer?: Buffer, initialOffset?: number): Buffer {
return this.__toBuffer(buffer, initialOffset, true)
}
__toBuffer (buffer: Buffer | void, initialOffset: number | void, __allowWitness: boolean | void): Buffer {
__toBuffer (buffer?: Buffer, initialOffset?: number, __allowWitness?: boolean): Buffer {
if (!buffer) buffer = <Buffer> Buffer.allocUnsafe(this.__byteLength((<boolean>__allowWitness)))
let offset = initialOffset || 0
function writeSlice (slice) {
function writeSlice (slice: Buffer): void {
offset += slice.copy(buffer, offset)
}
function writeUInt8 (i) {
function writeUInt8 (i: number) {
offset = (<Buffer>buffer).writeUInt8(i, offset)
}
function writeUInt32 (i) {
function writeUInt32 (i: number) {
offset = (<Buffer>buffer).writeUInt32LE(i, offset)
}
function writeInt32 (i) {
function writeInt32 (i: number) {
offset = (<Buffer>buffer).writeInt32LE(i, offset)
}
function writeUInt64 (i) {
function writeUInt64 (i: number) {
offset = bufferutils.writeUInt64LE(buffer, i, offset)
}
function writeVarInt (i) {
function writeVarInt (i: number) {
varuint.encode(i, buffer, offset)
offset += varuint.encode.bytes
}
function writeVarSlice (slice) {
function writeVarSlice (slice: Buffer) {
writeVarInt(slice.length)
writeSlice(slice)
}
function writeVector (vector) {
function writeVector (vector: Array<Buffer>) {
writeVarInt(vector.length)
vector.forEach(writeVarSlice)
}
@ -555,13 +555,13 @@ export class Transaction {
return this.toBuffer(undefined, undefined).toString('hex')
}
setInputScript (index, scriptSig) {
setInputScript (index: number, scriptSig: Buffer) {
typeforce(types.tuple(types.Number, types.Buffer), arguments)
this.ins[index].script = scriptSig
}
setWitness (index, witness) {
setWitness (index: number, witness: Array<Buffer>) {
typeforce(types.tuple(types.Number, [types.Buffer]), arguments)
this.ins[index].witness = witness

View file

@ -2,6 +2,7 @@ import { Network } from './networks'
import * as networks from './networks'
import { Transaction, Output } from './transaction'
import { ECPairInterface } from './ecpair'
import * as types from './types'
const Buffer = require('safe-buffer').Buffer
const baddress = require('./address')
const bcrypto = require('./crypto')
@ -9,7 +10,6 @@ const bscript = require('./script')
const ops = require('bitcoin-ops')
const payments = require('./payments')
const typeforce = require('typeforce')
const types = require('./types')
const classify = require('./classify')
const SCRIPT_TYPES = classify.types
@ -53,7 +53,7 @@ function txIsTransaction(tx: Buffer | string | Transaction): tx is Transaction {
export class TransactionBuilder {
network: Network
maximumFeeRate: number
private __prevTxSet: Object
private __prevTxSet: { [index: string]: boolean }
private __inputs: Array<TxbInput>
private __tx: Transaction
@ -192,7 +192,7 @@ export class TransactionBuilder {
return vin
}
addOutput (scriptPubKey: string | Buffer, value): number {
addOutput (scriptPubKey: string | Buffer, value: number): number {
if (!this.__canModifyOutputs()) {
throw new Error('No, this would invalidate signatures')
}
@ -282,7 +282,7 @@ export class TransactionBuilder {
}
// ready to sign
let signatureHash
let signatureHash: Buffer
if (input.hasWitness) {
signatureHash = this.__tx.hashForWitnessV0(vin, input.signScript, input.value, hashType)
} else {
@ -573,7 +573,7 @@ function expandOutput (script: Buffer, ourPubKey?: Buffer): TxbOutput {
return {
type,
pubkeys: p2ms.pubkeys,
signatures: p2ms.pubkeys.map(() => undefined),
signatures: p2ms.pubkeys.map((): undefined => undefined),
maxSignatures: p2ms.m
}
}

View file

@ -33,5 +33,17 @@ export const Network = typeforce.compile({
export const Buffer256bit = typeforce.BufferN(32)
export const Hash160bit = typeforce.BufferN(20)
export const Hash256bit = typeforce.BufferN(32)
export * from 'typeforce'
export { Number, Array } from 'typeforce'
export const Number = typeforce.Number
export const Array = typeforce.Array
export const Boolean = typeforce.Boolean
export const String = typeforce.String
export const Buffer = typeforce.Buffer
export const Hex = typeforce.Hex
export const maybe = typeforce.maybe
export const tuple = typeforce.tuple
export const UInt8 = typeforce.UInt8
export const UInt32 = typeforce.UInt32
export const Function = typeforce.Function
export const BufferN = typeforce.BufferN
export const Null = typeforce.Null
export const oneOf = typeforce.oneOf

View file

@ -9,7 +9,7 @@
],
"allowJs": false,
"strict": false,
"noImplicitAny": false,
"noImplicitAny": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"strictBindCallApply": true,