diff --git a/ts_src/payments/lazy.ts b/ts_src/payments/lazy.ts index fe0fb6d..1df181f 100644 --- a/ts_src/payments/lazy.ts +++ b/ts_src/payments/lazy.ts @@ -2,12 +2,12 @@ export function prop(object: {}, name: string, f: () => any): void { Object.defineProperty(object, name, { configurable: true, enumerable: true, - get() { + get(): any { const _value = f.call(this); this[name] = _value; return _value; }, - set(_value) { + set(_value: any): void { Object.defineProperty(this, name, { configurable: true, enumerable: true, diff --git a/ts_src/payments/p2ms.ts b/ts_src/payments/p2ms.ts index b8691c0..bac8b83 100644 --- a/ts_src/payments/p2ms.ts +++ b/ts_src/payments/p2ms.ts @@ -28,7 +28,7 @@ export function p2ms(a: Payment, opts?: PaymentOpts): Payment { throw new TypeError('Not enough data'); opts = Object.assign({ validate: true }, opts || {}); - function isAcceptableSignature(x: Buffer | number) { + function isAcceptableSignature(x: Buffer | number): boolean { return ( bscript.isCanonicalScriptSignature(x as Buffer) || (opts!.allowIncomplete && (x as number) === OPS.OP_0) !== undefined diff --git a/ts_src/script.ts b/ts_src/script.ts index 1c705d3..951f48b 100644 --- a/ts_src/script.ts +++ b/ts_src/script.ts @@ -26,7 +26,7 @@ function isPushOnlyChunk(value: number | Buffer): boolean { return types.Buffer(value) || isOPInt(value as number); } -export function isPushOnly(value: Stack) { +export function isPushOnly(value: Stack): boolean { return types.Array(value) && value.every(isPushOnlyChunk); } diff --git a/ts_src/templates/multisig/input.ts b/ts_src/templates/multisig/input.ts index 57b73d2..31fe416 100644 --- a/ts_src/templates/multisig/input.ts +++ b/ts_src/templates/multisig/input.ts @@ -26,6 +26,6 @@ export function check( bscript.isCanonicalScriptSignature, ); } -check.toJSON = () => { +check.toJSON = (): string => { return 'multisig input'; }; diff --git a/ts_src/templates/multisig/output.ts b/ts_src/templates/multisig/output.ts index 3ee0820..20c2162 100644 --- a/ts_src/templates/multisig/output.ts +++ b/ts_src/templates/multisig/output.ts @@ -28,6 +28,6 @@ export function check( const keys = chunks.slice(1, -2) as Buffer[]; return keys.every(bscript.isCanonicalPubKey); } -check.toJSON = () => { +check.toJSON = (): string => { return 'multi-sig output'; }; diff --git a/ts_src/templates/nulldata.ts b/ts_src/templates/nulldata.ts index bafe4a4..99b5c44 100644 --- a/ts_src/templates/nulldata.ts +++ b/ts_src/templates/nulldata.ts @@ -7,7 +7,7 @@ export function check(script: Buffer | Array): boolean { return buffer.length > 1 && buffer[0] === OPS.OP_RETURN; } -check.toJSON = () => { +check.toJSON = (): string => { return 'null data output'; }; diff --git a/ts_src/templates/pubkey/input.ts b/ts_src/templates/pubkey/input.ts index 7e07a94..745e6d9 100644 --- a/ts_src/templates/pubkey/input.ts +++ b/ts_src/templates/pubkey/input.ts @@ -11,6 +11,6 @@ export function check(script: Buffer | Stack): boolean { bscript.isCanonicalScriptSignature(chunks[0] as Buffer) ); } -check.toJSON = () => { +check.toJSON = (): string => { return 'pubKey input'; }; diff --git a/ts_src/templates/pubkey/output.ts b/ts_src/templates/pubkey/output.ts index d57422d..1b2c391 100644 --- a/ts_src/templates/pubkey/output.ts +++ b/ts_src/templates/pubkey/output.ts @@ -13,6 +13,6 @@ export function check(script: Buffer | Stack): boolean { chunks[1] === OPS.OP_CHECKSIG ); } -check.toJSON = () => { +check.toJSON = (): string => { return 'pubKey output'; }; diff --git a/ts_src/templates/pubkeyhash/input.ts b/ts_src/templates/pubkeyhash/input.ts index 83da475..de93968 100644 --- a/ts_src/templates/pubkeyhash/input.ts +++ b/ts_src/templates/pubkeyhash/input.ts @@ -12,6 +12,6 @@ export function check(script: Buffer | Stack): boolean { bscript.isCanonicalPubKey(chunks[1] as Buffer) ); } -check.toJSON = () => { +check.toJSON = (): string => { return 'pubKeyHash input'; }; diff --git a/ts_src/templates/pubkeyhash/output.ts b/ts_src/templates/pubkeyhash/output.ts index 37070a3..248c210 100644 --- a/ts_src/templates/pubkeyhash/output.ts +++ b/ts_src/templates/pubkeyhash/output.ts @@ -15,6 +15,6 @@ export function check(script: Buffer | Array): boolean { buffer[24] === OPS.OP_CHECKSIG ); } -check.toJSON = () => { +check.toJSON = (): string => { return 'pubKeyHash output'; }; diff --git a/ts_src/templates/scripthash/input.ts b/ts_src/templates/scripthash/input.ts index 1e3f97d..3ef8aab 100644 --- a/ts_src/templates/scripthash/input.ts +++ b/ts_src/templates/scripthash/input.ts @@ -56,6 +56,6 @@ export function check( return false; } -check.toJSON = () => { +check.toJSON = (): string => { return 'scriptHash input'; }; diff --git a/ts_src/templates/scripthash/output.ts b/ts_src/templates/scripthash/output.ts index 7eac30d..aea8e24 100644 --- a/ts_src/templates/scripthash/output.ts +++ b/ts_src/templates/scripthash/output.ts @@ -13,6 +13,6 @@ export function check(script: Buffer | Array): boolean { buffer[22] === OPS.OP_EQUAL ); } -check.toJSON = () => { +check.toJSON = (): string => { return 'scriptHash output'; }; diff --git a/ts_src/templates/witnesscommitment/output.ts b/ts_src/templates/witnesscommitment/output.ts index 9439e4c..482798f 100644 --- a/ts_src/templates/witnesscommitment/output.ts +++ b/ts_src/templates/witnesscommitment/output.ts @@ -19,7 +19,7 @@ export function check(script: Buffer | Array): boolean { ); } -check.toJSON = () => { +check.toJSON = (): string => { return 'Witness commitment output'; }; diff --git a/ts_src/templates/witnesspubkeyhash/input.ts b/ts_src/templates/witnesspubkeyhash/input.ts index aa3bef8..26fe63d 100644 --- a/ts_src/templates/witnesspubkeyhash/input.ts +++ b/ts_src/templates/witnesspubkeyhash/input.ts @@ -16,6 +16,6 @@ export function check(script: Buffer | Stack): boolean { isCompressedCanonicalPubKey(chunks[1] as Buffer) ); } -check.toJSON = () => { +check.toJSON = (): string => { return 'witnessPubKeyHash input'; }; diff --git a/ts_src/templates/witnesspubkeyhash/output.ts b/ts_src/templates/witnesspubkeyhash/output.ts index 0e9432c..bfd6690 100644 --- a/ts_src/templates/witnesspubkeyhash/output.ts +++ b/ts_src/templates/witnesspubkeyhash/output.ts @@ -8,6 +8,6 @@ export function check(script: Buffer | Array): boolean { return buffer.length === 22 && buffer[0] === OPS.OP_0 && buffer[1] === 0x14; } -check.toJSON = () => { +check.toJSON = (): string => { return 'Witness pubKeyHash output'; }; diff --git a/ts_src/templates/witnessscripthash/input.ts b/ts_src/templates/witnessscripthash/input.ts index 42a13ac..0f63330 100644 --- a/ts_src/templates/witnessscripthash/input.ts +++ b/ts_src/templates/witnessscripthash/input.ts @@ -42,6 +42,6 @@ export function check(chunks: Buffer[], allowIncomplete?: boolean): boolean { return false; } -check.toJSON = () => { +check.toJSON = (): string => { return 'witnessScriptHash input'; }; diff --git a/ts_src/templates/witnessscripthash/output.ts b/ts_src/templates/witnessscripthash/output.ts index 85034d1..7d4f33a 100644 --- a/ts_src/templates/witnessscripthash/output.ts +++ b/ts_src/templates/witnessscripthash/output.ts @@ -8,6 +8,6 @@ export function check(script: Buffer | Array): boolean { return buffer.length === 34 && buffer[0] === OPS.OP_0 && buffer[1] === 0x20; } -check.toJSON = () => { +check.toJSON = (): string => { return 'Witness scriptHash output'; }; diff --git a/ts_src/transaction.ts b/ts_src/transaction.ts index b788d91..218d004 100644 --- a/ts_src/transaction.ts +++ b/ts_src/transaction.ts @@ -497,17 +497,17 @@ export class Transaction { return this.__toBuffer(buffer, initialOffset, true); } - toHex() { + toHex(): string { return this.toBuffer(undefined, undefined).toString('hex'); } - setInputScript(index: number, scriptSig: Buffer) { + setInputScript(index: number, scriptSig: Buffer): void { typeforce(types.tuple(types.Number, types.Buffer), arguments); this.ins[index].script = scriptSig; } - setWitness(index: number, witness: Buffer[]) { + setWitness(index: number, witness: Buffer[]): void { typeforce(types.tuple(types.Number, [types.Buffer]), arguments); this.ins[index].witness = witness; @@ -548,33 +548,33 @@ export class Transaction { offset += slice.copy(buffer!, offset); } - function writeUInt8(i: number) { + function writeUInt8(i: number): void { offset = buffer!.writeUInt8(i, offset); } - function writeUInt32(i: number) { + function writeUInt32(i: number): void { offset = buffer!.writeUInt32LE(i, offset); } - function writeInt32(i: number) { + function writeInt32(i: number): void { offset = buffer!.writeInt32LE(i, offset); } - function writeUInt64(i: number) { + function writeUInt64(i: number): void { offset = bufferutils.writeUInt64LE(buffer!, i, offset); } - function writeVarInt(i: number) { + function writeVarInt(i: number): void { varuint.encode(i, buffer, offset); offset += varuint.encode.bytes; } - function writeVarSlice(slice: Buffer) { + function writeVarSlice(slice: Buffer): void { writeVarInt(slice.length); writeSlice(slice); } - function writeVector(vector: Buffer[]) { + function writeVector(vector: Buffer[]): void { writeVarInt(vector.length); vector.forEach(writeVarSlice); } diff --git a/ts_src/transaction_builder.ts b/ts_src/transaction_builder.ts index 575fbc2..2367250 100644 --- a/ts_src/transaction_builder.ts +++ b/ts_src/transaction_builder.ts @@ -192,7 +192,7 @@ export class TransactionBuilder { hashType: number, witnessValue: number, witnessScript: Buffer, - ) { + ): void { // TODO: remove keyPair.network matching in 4.0.0 if (keyPair.network && keyPair.network !== this.network) throw new TypeError('Inconsistent network'); diff --git a/ts_src/types.ts b/ts_src/types.ts index 033e62a..06c247d 100644 --- a/ts_src/types.ts +++ b/ts_src/types.ts @@ -8,7 +8,7 @@ export function UInt31(value: number): boolean { export function BIP32Path(value: string): boolean { return typeforce.String(value) && !!value.match(/^(m\/)?(\d+'?\/)*\d+'?$/); } -BIP32Path.toJSON = () => { +BIP32Path.toJSON = (): string => { return 'BIP32 derivation path'; }; diff --git a/tslint.json b/tslint.json index 9708e8b..1ba998d 100644 --- a/tslint.json +++ b/tslint.json @@ -22,6 +22,12 @@ "no-unused-expression": false, "object-literal-sort-keys": false, "quotemark": [true, "single"], + "typedef": [ + true, + "call-signature", + "arrow-call-signature", + "property-declaration" + ], "variable-name": [ true, "ban-keywords",