Browse Source

Fix lint for templates

fixTypes
junderw 6 years ago
parent
commit
08c4d6ac7d
No known key found for this signature in database GPG Key ID: B256185D3A971908
  1. 2
      src/templates/multisig/input.js
  2. 4
      src/templates/multisig/output.js
  3. 2
      src/templates/nulldata.js
  4. 5
      src/templates/pubkey/input.js
  5. 2
      src/templates/pubkey/output.js
  6. 2
      src/templates/pubkeyhash/input.js
  7. 2
      src/templates/pubkeyhash/output.js
  8. 2
      src/templates/scripthash/input.js
  9. 2
      src/templates/scripthash/output.js
  10. 4
      src/templates/witnesscommitment/output.js
  11. 2
      src/templates/witnesspubkeyhash/input.js
  12. 2
      src/templates/witnesspubkeyhash/output.js
  13. 2
      src/templates/witnessscripthash/input.js
  14. 2
      src/templates/witnessscripthash/output.js
  15. 11
      ts_src/templates/multisig/input.ts
  16. 15
      ts_src/templates/multisig/output.ts
  17. 2
      ts_src/templates/nulldata.ts
  18. 10
      ts_src/templates/pubkey/input.ts
  19. 9
      ts_src/templates/pubkey/output.ts
  20. 11
      ts_src/templates/pubkeyhash/input.ts
  21. 2
      ts_src/templates/pubkeyhash/output.ts
  22. 2
      ts_src/templates/scripthash/input.ts
  23. 2
      ts_src/templates/scripthash/output.ts
  24. 6
      ts_src/templates/witnesscommitment/output.ts
  25. 11
      ts_src/templates/witnesspubkeyhash/input.ts
  26. 2
      ts_src/templates/witnesspubkeyhash/output.ts
  27. 7
      ts_src/templates/witnessscripthash/input.ts
  28. 2
      ts_src/templates/witnessscripthash/output.ts
  29. 3
      types/templates/multisig/input.d.ts
  30. 3
      types/templates/multisig/output.d.ts
  31. 3
      types/templates/pubkey/input.d.ts
  32. 3
      types/templates/pubkey/output.d.ts
  33. 3
      types/templates/pubkeyhash/input.d.ts
  34. 3
      types/templates/witnesspubkeyhash/input.d.ts
  35. 2
      types/templates/witnessscripthash/input.d.ts

2
src/templates/multisig/input.js

@ -18,6 +18,6 @@ function check(script, allowIncomplete) {
return chunks.slice(1).every(bscript.isCanonicalScriptSignature); return chunks.slice(1).every(bscript.isCanonicalScriptSignature);
} }
exports.check = check; exports.check = check;
check.toJSON = function () { check.toJSON = () => {
return 'multisig input'; return 'multisig input';
}; };

4
src/templates/multisig/output.js

@ -2,8 +2,8 @@
// m [pubKeys ...] n OP_CHECKMULTISIG // m [pubKeys ...] n OP_CHECKMULTISIG
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const bscript = require("../../script"); const bscript = require("../../script");
const types = require("../../types");
const script_1 = require("../../script"); const script_1 = require("../../script");
const types = require("../../types");
const OP_INT_BASE = script_1.OPS.OP_RESERVED; // OP_1 - 1 const OP_INT_BASE = script_1.OPS.OP_RESERVED; // OP_1 - 1
function check(script, allowIncomplete) { function check(script, allowIncomplete) {
const chunks = bscript.decompile(script); const chunks = bscript.decompile(script);
@ -31,6 +31,6 @@ function check(script, allowIncomplete) {
return keys.every(bscript.isCanonicalPubKey); return keys.every(bscript.isCanonicalPubKey);
} }
exports.check = check; exports.check = check;
check.toJSON = function () { check.toJSON = () => {
return 'multi-sig output'; return 'multi-sig output';
}; };

2
src/templates/nulldata.js

@ -8,7 +8,7 @@ function check(script) {
return buffer.length > 1 && buffer[0] === OPS.OP_RETURN; return buffer.length > 1 && buffer[0] === OPS.OP_RETURN;
} }
exports.check = check; exports.check = check;
check.toJSON = function () { check.toJSON = () => {
return 'null data output'; return 'null data output';
}; };
const output = { check }; const output = { check };

5
src/templates/pubkey/input.js

@ -4,9 +4,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
const bscript = require("../../script"); const bscript = require("../../script");
function check(script) { function check(script) {
const chunks = bscript.decompile(script); const chunks = bscript.decompile(script);
return (chunks.length === 1 && bscript.isCanonicalScriptSignature(chunks[0])); return (chunks.length === 1 &&
bscript.isCanonicalScriptSignature(chunks[0]));
} }
exports.check = check; exports.check = check;
check.toJSON = function () { check.toJSON = () => {
return 'pubKey input'; return 'pubKey input';
}; };

2
src/templates/pubkey/output.js

@ -10,6 +10,6 @@ function check(script) {
chunks[1] === script_1.OPS.OP_CHECKSIG); chunks[1] === script_1.OPS.OP_CHECKSIG);
} }
exports.check = check; exports.check = check;
check.toJSON = function () { check.toJSON = () => {
return 'pubKey output'; return 'pubKey output';
}; };

2
src/templates/pubkeyhash/input.js

@ -9,6 +9,6 @@ function check(script) {
bscript.isCanonicalPubKey(chunks[1])); bscript.isCanonicalPubKey(chunks[1]));
} }
exports.check = check; exports.check = check;
check.toJSON = function () { check.toJSON = () => {
return 'pubKeyHash input'; return 'pubKeyHash input';
}; };

2
src/templates/pubkeyhash/output.js

@ -13,6 +13,6 @@ function check(script) {
buffer[24] === script_1.OPS.OP_CHECKSIG); buffer[24] === script_1.OPS.OP_CHECKSIG);
} }
exports.check = check; exports.check = check;
check.toJSON = function () { check.toJSON = () => {
return 'pubKeyHash output'; return 'pubKeyHash output';
}; };

2
src/templates/scripthash/input.js

@ -39,6 +39,6 @@ function check(script, allowIncomplete) {
return false; return false;
} }
exports.check = check; exports.check = check;
check.toJSON = function () { check.toJSON = () => {
return 'scriptHash input'; return 'scriptHash input';
}; };

2
src/templates/scripthash/output.js

@ -11,6 +11,6 @@ function check(script) {
buffer[22] === script_1.OPS.OP_EQUAL); buffer[22] === script_1.OPS.OP_EQUAL);
} }
exports.check = check; exports.check = check;
check.toJSON = function () { check.toJSON = () => {
return 'scriptHash output'; return 'scriptHash output';
}; };

4
src/templates/witnesscommitment/output.js

@ -2,9 +2,9 @@
// OP_RETURN {aa21a9ed} {commitment} // OP_RETURN {aa21a9ed} {commitment}
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
const bscript = require("../../script"); const bscript = require("../../script");
const script_1 = require("../../script");
const types = require("../../types"); const types = require("../../types");
const typeforce = require('typeforce'); const typeforce = require('typeforce');
const script_1 = require("../../script");
const HEADER = Buffer.from('aa21a9ed', 'hex'); const HEADER = Buffer.from('aa21a9ed', 'hex');
function check(script) { function check(script) {
const buffer = bscript.compile(script); const buffer = bscript.compile(script);
@ -14,7 +14,7 @@ function check(script) {
buffer.slice(2, 6).equals(HEADER)); buffer.slice(2, 6).equals(HEADER));
} }
exports.check = check; exports.check = check;
check.toJSON = function () { check.toJSON = () => {
return 'Witness commitment output'; return 'Witness commitment output';
}; };
function encode(commitment) { function encode(commitment) {

2
src/templates/witnesspubkeyhash/input.js

@ -12,6 +12,6 @@ function check(script) {
isCompressedCanonicalPubKey(chunks[1])); isCompressedCanonicalPubKey(chunks[1]));
} }
exports.check = check; exports.check = check;
check.toJSON = function () { check.toJSON = () => {
return 'witnessPubKeyHash input'; return 'witnessPubKeyHash input';
}; };

2
src/templates/witnesspubkeyhash/output.js

@ -8,6 +8,6 @@ function check(script) {
return buffer.length === 22 && buffer[0] === script_1.OPS.OP_0 && buffer[1] === 0x14; return buffer.length === 22 && buffer[0] === script_1.OPS.OP_0 && buffer[1] === 0x14;
} }
exports.check = check; exports.check = check;
check.toJSON = function () { check.toJSON = () => {
return 'Witness pubKeyHash output'; return 'Witness pubKeyHash output';
}; };

2
src/templates/witnessscripthash/input.js

@ -31,6 +31,6 @@ function check(chunks, allowIncomplete) {
return false; return false;
} }
exports.check = check; exports.check = check;
check.toJSON = function () { check.toJSON = () => {
return 'witnessScriptHash input'; return 'witnessScriptHash input';
}; };

2
src/templates/witnessscripthash/output.js

@ -8,6 +8,6 @@ function check(script) {
return buffer.length === 34 && buffer[0] === script_1.OPS.OP_0 && buffer[1] === 0x20; return buffer.length === 34 && buffer[0] === script_1.OPS.OP_0 && buffer[1] === 0x20;
} }
exports.check = check; exports.check = check;
check.toJSON = function () { check.toJSON = () => {
return 'Witness scriptHash output'; return 'Witness scriptHash output';
}; };

11
ts_src/templates/multisig/input.ts

@ -1,19 +1,20 @@
// OP_0 [signatures ...] // OP_0 [signatures ...]
import { Stack } from '../../payments';
import * as bscript from '../../script'; import * as bscript from '../../script';
import { OPS } from '../../script'; import { OPS } from '../../script';
function partialSignature(value: number | Buffer): boolean { function partialSignature(value: number | Buffer): boolean {
return ( return (
value === OPS.OP_0 || bscript.isCanonicalScriptSignature(<Buffer>value) value === OPS.OP_0 || bscript.isCanonicalScriptSignature(value as Buffer)
); );
} }
export function check( export function check(
script: Buffer | Array<number | Buffer>, script: Buffer | Stack,
allowIncomplete?: boolean, allowIncomplete?: boolean,
): boolean { ): boolean {
const chunks = <Array<number | Buffer>>bscript.decompile(script); const chunks = bscript.decompile(script) as Stack;
if (chunks.length < 2) return false; if (chunks.length < 2) return false;
if (chunks[0] !== OPS.OP_0) return false; if (chunks[0] !== OPS.OP_0) return false;
@ -21,10 +22,10 @@ export function check(
return chunks.slice(1).every(partialSignature); return chunks.slice(1).every(partialSignature);
} }
return (<Array<Buffer>>chunks.slice(1)).every( return (chunks.slice(1) as Buffer[]).every(
bscript.isCanonicalScriptSignature, bscript.isCanonicalScriptSignature,
); );
} }
check.toJSON = function() { check.toJSON = () => {
return 'multisig input'; return 'multisig input';
}; };

15
ts_src/templates/multisig/output.ts

@ -1,22 +1,23 @@
// m [pubKeys ...] n OP_CHECKMULTISIG // m [pubKeys ...] n OP_CHECKMULTISIG
import { Stack } from '../../payments';
import * as bscript from '../../script'; import * as bscript from '../../script';
import * as types from '../../types';
import { OPS } from '../../script'; import { OPS } from '../../script';
import * as types from '../../types';
const OP_INT_BASE = OPS.OP_RESERVED; // OP_1 - 1 const OP_INT_BASE = OPS.OP_RESERVED; // OP_1 - 1
export function check( export function check(
script: Buffer | Array<number | Buffer>, script: Buffer | Stack,
allowIncomplete?: boolean, allowIncomplete?: boolean,
): boolean { ): boolean {
const chunks = <Array<number | Buffer>>bscript.decompile(script); const chunks = bscript.decompile(script) as Stack;
if (chunks.length < 4) return false; if (chunks.length < 4) return false;
if (chunks[chunks.length - 1] !== OPS.OP_CHECKMULTISIG) return false; if (chunks[chunks.length - 1] !== OPS.OP_CHECKMULTISIG) return false;
if (!types.Number(chunks[0])) return false; if (!types.Number(chunks[0])) return false;
if (!types.Number(chunks[chunks.length - 2])) return false; if (!types.Number(chunks[chunks.length - 2])) return false;
const m = <number>chunks[0] - OP_INT_BASE; const m = (chunks[0] as number) - OP_INT_BASE;
const n = <number>chunks[chunks.length - 2] - OP_INT_BASE; const n = (chunks[chunks.length - 2] as number) - OP_INT_BASE;
if (m <= 0) return false; if (m <= 0) return false;
if (n > 16) return false; if (n > 16) return false;
@ -24,9 +25,9 @@ export function check(
if (n !== chunks.length - 3) return false; if (n !== chunks.length - 3) return false;
if (allowIncomplete) return true; if (allowIncomplete) return true;
const keys = <Array<Buffer>>chunks.slice(1, -2); const keys = chunks.slice(1, -2) as Buffer[];
return keys.every(bscript.isCanonicalPubKey); return keys.every(bscript.isCanonicalPubKey);
} }
check.toJSON = function() { check.toJSON = () => {
return 'multi-sig output'; return 'multi-sig output';
}; };

2
ts_src/templates/nulldata.ts

@ -7,7 +7,7 @@ export function check(script: Buffer | Array<number | Buffer>): boolean {
return buffer.length > 1 && buffer[0] === OPS.OP_RETURN; return buffer.length > 1 && buffer[0] === OPS.OP_RETURN;
} }
check.toJSON = function() { check.toJSON = () => {
return 'null data output'; return 'null data output';
}; };

10
ts_src/templates/pubkey/input.ts

@ -1,14 +1,16 @@
// {signature} // {signature}
import { Stack } from '../../payments';
import * as bscript from '../../script'; import * as bscript from '../../script';
export function check(script: Buffer | Array<number | Buffer>): boolean { export function check(script: Buffer | Stack): boolean {
const chunks = <Array<number | Buffer>>bscript.decompile(script); const chunks = bscript.decompile(script) as Stack;
return ( return (
chunks.length === 1 && bscript.isCanonicalScriptSignature(<Buffer>chunks[0]) chunks.length === 1 &&
bscript.isCanonicalScriptSignature(chunks[0] as Buffer)
); );
} }
check.toJSON = function() { check.toJSON = () => {
return 'pubKey input'; return 'pubKey input';
}; };

9
ts_src/templates/pubkey/output.ts

@ -1,17 +1,18 @@
// {pubKey} OP_CHECKSIG // {pubKey} OP_CHECKSIG
import { Stack } from '../../payments';
import * as bscript from '../../script'; import * as bscript from '../../script';
import { OPS } from '../../script'; import { OPS } from '../../script';
export function check(script: Buffer | Array<number | Buffer>): boolean { export function check(script: Buffer | Stack): boolean {
const chunks = <Array<number | Buffer>>bscript.decompile(script); const chunks = bscript.decompile(script) as Stack;
return ( return (
chunks.length === 2 && chunks.length === 2 &&
bscript.isCanonicalPubKey(<Buffer>chunks[0]) && bscript.isCanonicalPubKey(chunks[0] as Buffer) &&
chunks[1] === OPS.OP_CHECKSIG chunks[1] === OPS.OP_CHECKSIG
); );
} }
check.toJSON = function() { check.toJSON = () => {
return 'pubKey output'; return 'pubKey output';
}; };

11
ts_src/templates/pubkeyhash/input.ts

@ -1,16 +1,17 @@
// {signature} {pubKey} // {signature} {pubKey}
import { Stack } from '../../payments';
import * as bscript from '../../script'; import * as bscript from '../../script';
export function check(script: Buffer | Array<number | Buffer>): boolean { export function check(script: Buffer | Stack): boolean {
const chunks = <Array<number | Buffer>>bscript.decompile(script); const chunks = bscript.decompile(script) as Stack;
return ( return (
chunks.length === 2 && chunks.length === 2 &&
bscript.isCanonicalScriptSignature(<Buffer>chunks[0]) && bscript.isCanonicalScriptSignature(chunks[0] as Buffer) &&
bscript.isCanonicalPubKey(<Buffer>chunks[1]) bscript.isCanonicalPubKey(chunks[1] as Buffer)
); );
} }
check.toJSON = function() { check.toJSON = () => {
return 'pubKeyHash input'; return 'pubKeyHash input';
}; };

2
ts_src/templates/pubkeyhash/output.ts

@ -15,6 +15,6 @@ export function check(script: Buffer | Array<number | Buffer>): boolean {
buffer[24] === OPS.OP_CHECKSIG buffer[24] === OPS.OP_CHECKSIG
); );
} }
check.toJSON = function() { check.toJSON = () => {
return 'pubKeyHash output'; return 'pubKeyHash output';
}; };

2
ts_src/templates/scripthash/input.ts

@ -56,6 +56,6 @@ export function check(
return false; return false;
} }
check.toJSON = function() { check.toJSON = () => {
return 'scriptHash input'; return 'scriptHash input';
}; };

2
ts_src/templates/scripthash/output.ts

@ -13,6 +13,6 @@ export function check(script: Buffer | Array<number | Buffer>): boolean {
buffer[22] === OPS.OP_EQUAL buffer[22] === OPS.OP_EQUAL
); );
} }
check.toJSON = function() { check.toJSON = () => {
return 'scriptHash output'; return 'scriptHash output';
}; };

6
ts_src/templates/witnesscommitment/output.ts

@ -1,10 +1,10 @@
// OP_RETURN {aa21a9ed} {commitment} // OP_RETURN {aa21a9ed} {commitment}
import * as bscript from '../../script'; import * as bscript from '../../script';
import { OPS } from '../../script';
import * as types from '../../types'; import * as types from '../../types';
const typeforce = require('typeforce'); const typeforce = require('typeforce');
import { OPS } from '../../script';
const HEADER: Buffer = Buffer.from('aa21a9ed', 'hex'); const HEADER: Buffer = Buffer.from('aa21a9ed', 'hex');
@ -19,7 +19,7 @@ export function check(script: Buffer | Array<number | Buffer>): boolean {
); );
} }
check.toJSON = function() { check.toJSON = () => {
return 'Witness commitment output'; return 'Witness commitment output';
}; };
@ -36,5 +36,5 @@ export function encode(commitment: Buffer): Buffer {
export function decode(buffer: Buffer): Buffer { export function decode(buffer: Buffer): Buffer {
typeforce(check, buffer); typeforce(check, buffer);
return (<Buffer>bscript.decompile(buffer)![1]).slice(4, 36); return (bscript.decompile(buffer)![1] as Buffer).slice(4, 36);
} }

11
ts_src/templates/witnesspubkeyhash/input.ts

@ -1,20 +1,21 @@
// {signature} {pubKey} // {signature} {pubKey}
import { Stack } from '../../payments';
import * as bscript from '../../script'; import * as bscript from '../../script';
function isCompressedCanonicalPubKey(pubKey: Buffer): boolean { function isCompressedCanonicalPubKey(pubKey: Buffer): boolean {
return bscript.isCanonicalPubKey(pubKey) && pubKey.length === 33; return bscript.isCanonicalPubKey(pubKey) && pubKey.length === 33;
} }
export function check(script: Buffer | Array<number | Buffer>): boolean { export function check(script: Buffer | Stack): boolean {
const chunks = <Array<number | Buffer>>bscript.decompile(script); const chunks = bscript.decompile(script) as Stack;
return ( return (
chunks.length === 2 && chunks.length === 2 &&
bscript.isCanonicalScriptSignature(<Buffer>chunks[0]) && bscript.isCanonicalScriptSignature(chunks[0] as Buffer) &&
isCompressedCanonicalPubKey(<Buffer>chunks[1]) isCompressedCanonicalPubKey(chunks[1] as Buffer)
); );
} }
check.toJSON = function() { check.toJSON = () => {
return 'witnessPubKeyHash input'; return 'witnessPubKeyHash input';
}; };

2
ts_src/templates/witnesspubkeyhash/output.ts

@ -8,6 +8,6 @@ export function check(script: Buffer | Array<number | Buffer>): boolean {
return buffer.length === 22 && buffer[0] === OPS.OP_0 && buffer[1] === 0x14; return buffer.length === 22 && buffer[0] === OPS.OP_0 && buffer[1] === 0x14;
} }
check.toJSON = function() { check.toJSON = () => {
return 'Witness pubKeyHash output'; return 'Witness pubKeyHash output';
}; };

7
ts_src/templates/witnessscripthash/input.ts

@ -7,10 +7,7 @@ import * as p2ms from '../multisig';
import * as p2pk from '../pubkey'; import * as p2pk from '../pubkey';
import * as p2pkh from '../pubkeyhash'; import * as p2pkh from '../pubkeyhash';
export function check( export function check(chunks: Buffer[], allowIncomplete?: boolean): boolean {
chunks: Array<Buffer>,
allowIncomplete?: boolean,
): boolean {
typeforce(typeforce.Array, chunks); typeforce(typeforce.Array, chunks);
if (chunks.length < 1) return false; if (chunks.length < 1) return false;
@ -45,6 +42,6 @@ export function check(
return false; return false;
} }
check.toJSON = function() { check.toJSON = () => {
return 'witnessScriptHash input'; return 'witnessScriptHash input';
}; };

2
ts_src/templates/witnessscripthash/output.ts

@ -8,6 +8,6 @@ export function check(script: Buffer | Array<number | Buffer>): boolean {
return buffer.length === 34 && buffer[0] === OPS.OP_0 && buffer[1] === 0x20; return buffer.length === 34 && buffer[0] === OPS.OP_0 && buffer[1] === 0x20;
} }
check.toJSON = function() { check.toJSON = () => {
return 'Witness scriptHash output'; return 'Witness scriptHash output';
}; };

3
types/templates/multisig/input.d.ts

@ -1,5 +1,6 @@
/// <reference types="node" /> /// <reference types="node" />
export declare function check(script: Buffer | Array<number | Buffer>, allowIncomplete?: boolean): boolean; import { Stack } from '../../payments';
export declare function check(script: Buffer | Stack, allowIncomplete?: boolean): boolean;
export declare namespace check { export declare namespace check {
var toJSON: () => string; var toJSON: () => string;
} }

3
types/templates/multisig/output.d.ts

@ -1,5 +1,6 @@
/// <reference types="node" /> /// <reference types="node" />
export declare function check(script: Buffer | Array<number | Buffer>, allowIncomplete?: boolean): boolean; import { Stack } from '../../payments';
export declare function check(script: Buffer | Stack, allowIncomplete?: boolean): boolean;
export declare namespace check { export declare namespace check {
var toJSON: () => string; var toJSON: () => string;
} }

3
types/templates/pubkey/input.d.ts

@ -1,5 +1,6 @@
/// <reference types="node" /> /// <reference types="node" />
export declare function check(script: Buffer | Array<number | Buffer>): boolean; import { Stack } from '../../payments';
export declare function check(script: Buffer | Stack): boolean;
export declare namespace check { export declare namespace check {
var toJSON: () => string; var toJSON: () => string;
} }

3
types/templates/pubkey/output.d.ts

@ -1,5 +1,6 @@
/// <reference types="node" /> /// <reference types="node" />
export declare function check(script: Buffer | Array<number | Buffer>): boolean; import { Stack } from '../../payments';
export declare function check(script: Buffer | Stack): boolean;
export declare namespace check { export declare namespace check {
var toJSON: () => string; var toJSON: () => string;
} }

3
types/templates/pubkeyhash/input.d.ts

@ -1,5 +1,6 @@
/// <reference types="node" /> /// <reference types="node" />
export declare function check(script: Buffer | Array<number | Buffer>): boolean; import { Stack } from '../../payments';
export declare function check(script: Buffer | Stack): boolean;
export declare namespace check { export declare namespace check {
var toJSON: () => string; var toJSON: () => string;
} }

3
types/templates/witnesspubkeyhash/input.d.ts

@ -1,5 +1,6 @@
/// <reference types="node" /> /// <reference types="node" />
export declare function check(script: Buffer | Array<number | Buffer>): boolean; import { Stack } from '../../payments';
export declare function check(script: Buffer | Stack): boolean;
export declare namespace check { export declare namespace check {
var toJSON: () => string; var toJSON: () => string;
} }

2
types/templates/witnessscripthash/input.d.ts

@ -1,5 +1,5 @@
/// <reference types="node" /> /// <reference types="node" />
export declare function check(chunks: Array<Buffer>, allowIncomplete?: boolean): boolean; export declare function check(chunks: Buffer[], allowIncomplete?: boolean): boolean;
export declare namespace check { export declare namespace check {
var toJSON: () => string; var toJSON: () => string;
} }

Loading…
Cancel
Save