diff --git a/package.json b/package.json index 669233e..e704249 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "standard": "standard", "test": "npm run build && npm run standard && npm run coverage", "unit": "npm run build && mocha", - "build": "tsc -p tsconfig.json" + "build": "tsc -d -p tsconfig.json" }, "repository": { "type": "git", diff --git a/src/templates/nulldata.ts b/src/templates/nulldata.ts index 145b504..48b0365 100644 --- a/src/templates/nulldata.ts +++ b/src/templates/nulldata.ts @@ -3,7 +3,7 @@ const bscript = require('../script') const OPS = require('bitcoin-ops') -function check (script) { +export function check (script) { const buffer = bscript.compile(script) return buffer.length > 1 && @@ -11,5 +11,8 @@ function check (script) { } check.toJSON = function () { return 'null data output' } -module.exports = { output: { check: check } } -export {} +const output = { check } + +export { + output +} diff --git a/src/types.ts b/src/types.ts index 9fff4a6..57431ca 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,25 +1,25 @@ const typeforce = require('typeforce') -const UINT31_MAX = Math.pow(2, 31) - 1 -function UInt31 (value) { +const UINT31_MAX: number = Math.pow(2, 31) - 1 +export function UInt31 (value: number): boolean { return typeforce.UInt32(value) && value <= UINT31_MAX } -function BIP32Path (value) { - return typeforce.String(value) && value.match(/^(m\/)?(\d+'?\/)*\d+'?$/) +export function BIP32Path (value: string): boolean { + return typeforce.String(value) && !!value.match(/^(m\/)?(\d+'?\/)*\d+'?$/) } BIP32Path.toJSON = function () { return 'BIP32 derivation path' } -const SATOSHI_MAX = 21 * 1e14 -function Satoshi (value) { +const SATOSHI_MAX: number = 21 * 1e14 +export function Satoshi (value: number): boolean { return typeforce.UInt53(value) && value <= SATOSHI_MAX } // external dependent types -const ECPoint = typeforce.quacksLike('Point') +export const ECPoint = typeforce.quacksLike('Point') // exposed, external API -const Network = typeforce.compile({ +export const Network = typeforce.compile({ messagePrefix: typeforce.oneOf(typeforce.Buffer, typeforce.String), bip32: { public: typeforce.UInt32, @@ -30,21 +30,7 @@ const Network = typeforce.compile({ wif: typeforce.UInt8 }) -// extend typeforce types with ours -const types = { - BIP32Path: BIP32Path, - Buffer256bit: typeforce.BufferN(32), - ECPoint: ECPoint, - Hash160bit: typeforce.BufferN(20), - Hash256bit: typeforce.BufferN(32), - Network: Network, - Satoshi: Satoshi, - UInt31: UInt31 -} - -for (var typeName in typeforce) { - types[typeName] = typeforce[typeName] -} - -module.exports = types -export {} +export const Buffer256bit = typeforce.BufferN(32) +export const Hash160bit = typeforce.BufferN(20) +export const Hash256bit = typeforce.BufferN(32) +export * from 'typeforce' diff --git a/tsconfig.json b/tsconfig.json index f358d14..8803b83 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,12 +7,12 @@ "types": [ "node" ], - "allowJs": true, + "allowJs": false, "strict": false, "noImplicitAny": false, "strictNullChecks": false, - "strictFunctionTypes": false, - "strictBindCallApply": false, + "strictFunctionTypes": true, + "strictBindCallApply": true, "strictPropertyInitialization": false, "noImplicitThis": false, "alwaysStrict": false,