Remove AllowJS and get definitions
This commit is contained in:
parent
d684a6b2ef
commit
b4d54af0fe
4 changed files with 22 additions and 33 deletions
|
@ -21,7 +21,7 @@
|
||||||
"standard": "standard",
|
"standard": "standard",
|
||||||
"test": "npm run build && npm run standard && npm run coverage",
|
"test": "npm run build && npm run standard && npm run coverage",
|
||||||
"unit": "npm run build && mocha",
|
"unit": "npm run build && mocha",
|
||||||
"build": "tsc -p tsconfig.json"
|
"build": "tsc -d -p tsconfig.json"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
const bscript = require('../script')
|
const bscript = require('../script')
|
||||||
const OPS = require('bitcoin-ops')
|
const OPS = require('bitcoin-ops')
|
||||||
|
|
||||||
function check (script) {
|
export function check (script) {
|
||||||
const buffer = bscript.compile(script)
|
const buffer = bscript.compile(script)
|
||||||
|
|
||||||
return buffer.length > 1 &&
|
return buffer.length > 1 &&
|
||||||
|
@ -11,5 +11,8 @@ function check (script) {
|
||||||
}
|
}
|
||||||
check.toJSON = function () { return 'null data output' }
|
check.toJSON = function () { return 'null data output' }
|
||||||
|
|
||||||
module.exports = { output: { check: check } }
|
const output = { check }
|
||||||
export {}
|
|
||||||
|
export {
|
||||||
|
output
|
||||||
|
}
|
||||||
|
|
38
src/types.ts
38
src/types.ts
|
@ -1,25 +1,25 @@
|
||||||
const typeforce = require('typeforce')
|
const typeforce = require('typeforce')
|
||||||
|
|
||||||
const UINT31_MAX = Math.pow(2, 31) - 1
|
const UINT31_MAX: number = Math.pow(2, 31) - 1
|
||||||
function UInt31 (value) {
|
export function UInt31 (value: number): boolean {
|
||||||
return typeforce.UInt32(value) && value <= UINT31_MAX
|
return typeforce.UInt32(value) && value <= UINT31_MAX
|
||||||
}
|
}
|
||||||
|
|
||||||
function BIP32Path (value) {
|
export function BIP32Path (value: string): boolean {
|
||||||
return typeforce.String(value) && value.match(/^(m\/)?(\d+'?\/)*\d+'?$/)
|
return typeforce.String(value) && !!value.match(/^(m\/)?(\d+'?\/)*\d+'?$/)
|
||||||
}
|
}
|
||||||
BIP32Path.toJSON = function () { return 'BIP32 derivation path' }
|
BIP32Path.toJSON = function () { return 'BIP32 derivation path' }
|
||||||
|
|
||||||
const SATOSHI_MAX = 21 * 1e14
|
const SATOSHI_MAX: number = 21 * 1e14
|
||||||
function Satoshi (value) {
|
export function Satoshi (value: number): boolean {
|
||||||
return typeforce.UInt53(value) && value <= SATOSHI_MAX
|
return typeforce.UInt53(value) && value <= SATOSHI_MAX
|
||||||
}
|
}
|
||||||
|
|
||||||
// external dependent types
|
// external dependent types
|
||||||
const ECPoint = typeforce.quacksLike('Point')
|
export const ECPoint = typeforce.quacksLike('Point')
|
||||||
|
|
||||||
// exposed, external API
|
// exposed, external API
|
||||||
const Network = typeforce.compile({
|
export const Network = typeforce.compile({
|
||||||
messagePrefix: typeforce.oneOf(typeforce.Buffer, typeforce.String),
|
messagePrefix: typeforce.oneOf(typeforce.Buffer, typeforce.String),
|
||||||
bip32: {
|
bip32: {
|
||||||
public: typeforce.UInt32,
|
public: typeforce.UInt32,
|
||||||
|
@ -30,21 +30,7 @@ const Network = typeforce.compile({
|
||||||
wif: typeforce.UInt8
|
wif: typeforce.UInt8
|
||||||
})
|
})
|
||||||
|
|
||||||
// extend typeforce types with ours
|
export const Buffer256bit = typeforce.BufferN(32)
|
||||||
const types = {
|
export const Hash160bit = typeforce.BufferN(20)
|
||||||
BIP32Path: BIP32Path,
|
export const Hash256bit = typeforce.BufferN(32)
|
||||||
Buffer256bit: typeforce.BufferN(32),
|
export * from 'typeforce'
|
||||||
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 {}
|
|
||||||
|
|
|
@ -7,12 +7,12 @@
|
||||||
"types": [
|
"types": [
|
||||||
"node"
|
"node"
|
||||||
],
|
],
|
||||||
"allowJs": true,
|
"allowJs": false,
|
||||||
"strict": false,
|
"strict": false,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"strictNullChecks": false,
|
"strictNullChecks": false,
|
||||||
"strictFunctionTypes": false,
|
"strictFunctionTypes": true,
|
||||||
"strictBindCallApply": false,
|
"strictBindCallApply": true,
|
||||||
"strictPropertyInitialization": false,
|
"strictPropertyInitialization": false,
|
||||||
"noImplicitThis": false,
|
"noImplicitThis": false,
|
||||||
"alwaysStrict": false,
|
"alwaysStrict": false,
|
||||||
|
|
Loading…
Reference in a new issue