Merge pull request #1353 from d-yokoi/prettier

style: fix glob pattern for prettier
This commit is contained in:
Jonathan Underwood 2019-03-07 10:27:36 +09:00 committed by GitHub
commit 03f86a6a54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 240 additions and 190 deletions

View file

@ -28,7 +28,7 @@
"nobuild:integration": "mocha --timeout 50000 test/integration/", "nobuild:integration": "mocha --timeout 50000 test/integration/",
"nobuild:unit": "mocha", "nobuild:unit": "mocha",
"prepare": "npm run build", "prepare": "npm run build",
"prettier": "prettier ts_src/*.ts ts_src/**/*.ts --ignore-path ./.prettierignore", "prettier": "prettier 'ts_src/**/*.ts' --ignore-path ./.prettierignore",
"test": "npm run build && npm run format:ci && npm run nobuild:coverage", "test": "npm run build && npm run format:ci && npm run nobuild:coverage",
"unit": "npm run build && npm run nobuild:unit" "unit": "npm run build && npm run nobuild:unit"
}, },

View file

@ -1,7 +1,4 @@
import * as input from './input' import * as input from './input';
import * as output from './output' import * as output from './output';
export { export { input, output };
input,
output,
}

View file

@ -1,21 +1,30 @@
// OP_0 [signatures ...] // OP_0 [signatures ...]
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 value === OPS.OP_0 || bscript.isCanonicalScriptSignature(<Buffer>value) return (
value === OPS.OP_0 || bscript.isCanonicalScriptSignature(<Buffer>value)
);
} }
export function check (script: Buffer | Array<number | Buffer>, allowIncomplete?: boolean): boolean { export function check(
const chunks = <Array<number | Buffer>>bscript.decompile(script) script: Buffer | Array<number | Buffer>,
if (chunks.length < 2) return false allowIncomplete?: boolean,
if (chunks[0] !== OPS.OP_0) return false ): boolean {
const chunks = <Array<number | Buffer>>bscript.decompile(script);
if (chunks.length < 2) return false;
if (chunks[0] !== OPS.OP_0) return false;
if (allowIncomplete) { if (allowIncomplete) {
return chunks.slice(1).every(partialSignature) return chunks.slice(1).every(partialSignature);
} }
return (<Array<Buffer>>chunks.slice(1)).every(bscript.isCanonicalScriptSignature) return (<Array<Buffer>>chunks.slice(1)).every(
bscript.isCanonicalScriptSignature,
);
} }
check.toJSON = function () { return 'multisig input' } check.toJSON = function() {
return 'multisig input';
};

View file

@ -1,27 +1,32 @@
// m [pubKeys ...] n OP_CHECKMULTISIG // m [pubKeys ...] n OP_CHECKMULTISIG
import * as bscript from '../../script' import * as bscript from '../../script';
import * as types from '../../types' import * as types from '../../types';
import { OPS } from '../../script' import { OPS } from '../../script';
const OP_INT_BASE = OPS.OP_RESERVED // OP_1 - 1 const OP_INT_BASE = OPS.OP_RESERVED; // OP_1 - 1
export function check (script: Buffer | Array<number | Buffer>, allowIncomplete?: boolean): boolean { export function check(
const chunks = <Array<number | Buffer>>bscript.decompile(script) script: Buffer | Array<number | Buffer>,
allowIncomplete?: boolean,
): boolean {
const chunks = <Array<number | Buffer>>bscript.decompile(script);
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 = <number>chunks[0] - OP_INT_BASE;
const n = <number>chunks[chunks.length - 2] - OP_INT_BASE const n = <number>chunks[chunks.length - 2] - OP_INT_BASE;
if (m <= 0) return false if (m <= 0) return false;
if (n > 16) return false if (n > 16) return false;
if (m > n) return false if (m > n) return false;
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 = <Array<Buffer>>chunks.slice(1, -2);
return keys.every(bscript.isCanonicalPubKey) return keys.every(bscript.isCanonicalPubKey);
} }
check.toJSON = function () { return 'multi-sig output' } check.toJSON = function() {
return 'multi-sig output';
};

View file

@ -1,7 +1,4 @@
import * as input from './input' import * as input from './input';
import * as output from './output' import * as output from './output';
export { export { input, output };
input,
output,
}

View file

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

View file

@ -1,13 +1,17 @@
// {pubKey} OP_CHECKSIG // {pubKey} OP_CHECKSIG
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 | Array<number | Buffer>): boolean {
const chunks = <Array<number | Buffer>>bscript.decompile(script) const chunks = <Array<number | Buffer>>bscript.decompile(script);
return chunks.length === 2 && return (
chunks.length === 2 &&
bscript.isCanonicalPubKey(<Buffer>chunks[0]) && bscript.isCanonicalPubKey(<Buffer>chunks[0]) &&
chunks[1] === OPS.OP_CHECKSIG chunks[1] === OPS.OP_CHECKSIG
);
} }
check.toJSON = function () { return 'pubKey output' } check.toJSON = function() {
return 'pubKey output';
};

View file

@ -1,7 +1,4 @@
import * as input from './input' import * as input from './input';
import * as output from './output' import * as output from './output';
export { export { input, output };
input,
output,
}

View file

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

View file

@ -1,16 +1,20 @@
// OP_DUP OP_HASH160 {pubKeyHash} OP_EQUALVERIFY OP_CHECKSIG // OP_DUP OP_HASH160 {pubKeyHash} OP_EQUALVERIFY OP_CHECKSIG
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 | Array<number | Buffer>): boolean {
const buffer = bscript.compile(script) const buffer = bscript.compile(script);
return buffer.length === 25 && return (
buffer.length === 25 &&
buffer[0] === OPS.OP_DUP && buffer[0] === OPS.OP_DUP &&
buffer[1] === OPS.OP_HASH160 && buffer[1] === OPS.OP_HASH160 &&
buffer[2] === 0x14 && buffer[2] === 0x14 &&
buffer[23] === OPS.OP_EQUALVERIFY && buffer[23] === OPS.OP_EQUALVERIFY &&
buffer[24] === OPS.OP_CHECKSIG buffer[24] === OPS.OP_CHECKSIG
);
} }
check.toJSON = function () { return 'pubKeyHash output' } check.toJSON = function() {
return 'pubKeyHash output';
};

View file

@ -1,7 +1,4 @@
import * as input from './input' import * as input from './input';
import * as output from './output' import * as output from './output';
export { export { input, output };
input,
output,
}

View file

@ -1,46 +1,61 @@
// <scriptSig> {serialized scriptPubKey script} // <scriptSig> {serialized scriptPubKey script}
import * as bscript from '../../script' import * as bscript from '../../script';
import * as p2ms from '../multisig' 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';
import * as p2wpkho from '../witnesspubkeyhash/output' import * as p2wpkho from '../witnesspubkeyhash/output';
import * as p2wsho from '../witnessscripthash/output' import * as p2wsho from '../witnessscripthash/output';
export function check(
script: Buffer | Array<number | Buffer>,
allowIncomplete?: boolean,
): boolean {
const chunks = bscript.decompile(script)!;
if (chunks.length < 1) return false;
const lastChunk = chunks[chunks.length - 1];
if (!Buffer.isBuffer(lastChunk)) return false;
export function check (script: Buffer | Array<number | Buffer>, allowIncomplete?: boolean): boolean { const scriptSigChunks = bscript.decompile(
const chunks = bscript.decompile(script)! bscript.compile(chunks.slice(0, -1)),
if (chunks.length < 1) return false )!;
const redeemScriptChunks = bscript.decompile(lastChunk);
const lastChunk = chunks[chunks.length - 1]
if (!Buffer.isBuffer(lastChunk)) return false
const scriptSigChunks = bscript.decompile(bscript.compile(chunks.slice(0, -1)))!
const redeemScriptChunks = bscript.decompile(lastChunk)
// is redeemScript a valid script? // is redeemScript a valid script?
if (!redeemScriptChunks) return false if (!redeemScriptChunks) return false;
// is redeemScriptSig push only? // is redeemScriptSig push only?
if (!bscript.isPushOnly(scriptSigChunks)) return false if (!bscript.isPushOnly(scriptSigChunks)) return false;
// is witness? // is witness?
if (chunks.length === 1) { if (chunks.length === 1) {
return p2wsho.check(redeemScriptChunks) || return (
p2wpkho.check(redeemScriptChunks) p2wsho.check(redeemScriptChunks) || p2wpkho.check(redeemScriptChunks)
);
} }
// match types // match types
if (p2pkh.input.check(scriptSigChunks) && if (
p2pkh.output.check(redeemScriptChunks)) return true p2pkh.input.check(scriptSigChunks) &&
p2pkh.output.check(redeemScriptChunks)
)
return true;
if (p2ms.input.check(scriptSigChunks, allowIncomplete) && if (
p2ms.output.check(redeemScriptChunks)) return true p2ms.input.check(scriptSigChunks, allowIncomplete) &&
p2ms.output.check(redeemScriptChunks)
)
return true;
if (p2pk.input.check(scriptSigChunks) && if (
p2pk.output.check(redeemScriptChunks)) return true p2pk.input.check(scriptSigChunks) &&
p2pk.output.check(redeemScriptChunks)
)
return true;
return false return false;
} }
check.toJSON = function () { return 'scriptHash input' } check.toJSON = function() {
return 'scriptHash input';
};

View file

@ -1,14 +1,18 @@
// OP_HASH160 {scriptHash} OP_EQUAL // OP_HASH160 {scriptHash} OP_EQUAL
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 | Array<number | Buffer>): boolean {
const buffer = bscript.compile(script) const buffer = bscript.compile(script);
return buffer.length === 23 && return (
buffer.length === 23 &&
buffer[0] === OPS.OP_HASH160 && buffer[0] === OPS.OP_HASH160 &&
buffer[1] === 0x14 && buffer[1] === 0x14 &&
buffer[22] === OPS.OP_EQUAL buffer[22] === OPS.OP_EQUAL
);
} }
check.toJSON = function () { return 'scriptHash output' } check.toJSON = function() {
return 'scriptHash output';
};

View file

@ -1,5 +1,3 @@
import * as output from './output' import * as output from './output';
export { export { output };
output,
}

View file

@ -1,36 +1,40 @@
// OP_RETURN {aa21a9ed} {commitment} // OP_RETURN {aa21a9ed} {commitment}
import * as bscript from '../../script' import * as bscript from '../../script';
import * as types from '../../types' import * as types from '../../types';
const typeforce = require('typeforce') const typeforce = require('typeforce');
import { OPS } from '../../script' import { OPS } from '../../script';
const HEADER: Buffer = Buffer.from('aa21a9ed', 'hex') const HEADER: Buffer = Buffer.from('aa21a9ed', 'hex');
export function check (script: Buffer | Array<number | Buffer>): boolean { export function check(script: Buffer | Array<number | Buffer>): boolean {
const buffer = bscript.compile(script) const buffer = bscript.compile(script);
return buffer.length > 37 && return (
buffer.length > 37 &&
buffer[0] === OPS.OP_RETURN && buffer[0] === OPS.OP_RETURN &&
buffer[1] === 0x24 && buffer[1] === 0x24 &&
buffer.slice(2, 6).equals(HEADER) buffer.slice(2, 6).equals(HEADER)
);
} }
check.toJSON = function () { return 'Witness commitment output' } check.toJSON = function() {
return 'Witness commitment output';
};
export function encode (commitment: Buffer): Buffer { export function encode(commitment: Buffer): Buffer {
typeforce(types.Hash256bit, commitment) typeforce(types.Hash256bit, commitment);
const buffer = Buffer.allocUnsafe(36) const buffer = Buffer.allocUnsafe(36);
HEADER.copy(buffer, 0) HEADER.copy(buffer, 0);
commitment.copy(buffer, 4) commitment.copy(buffer, 4);
return bscript.compile([OPS.OP_RETURN, buffer]) return bscript.compile([OPS.OP_RETURN, 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 (<Buffer>bscript.decompile(buffer)![1]).slice(4, 36);
} }

View file

@ -1,7 +1,4 @@
import * as input from './input' import * as input from './input';
import * as output from './output' import * as output from './output';
export { export { input, output };
input,
output,
}

View file

@ -1,16 +1,20 @@
// {signature} {pubKey} // {signature} {pubKey}
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 | Array<number | Buffer>): boolean {
const chunks = <Array<number | Buffer>>bscript.decompile(script) const chunks = <Array<number | Buffer>>bscript.decompile(script);
return chunks.length === 2 && return (
chunks.length === 2 &&
bscript.isCanonicalScriptSignature(<Buffer>chunks[0]) && bscript.isCanonicalScriptSignature(<Buffer>chunks[0]) &&
isCompressedCanonicalPubKey(<Buffer>chunks[1]) isCompressedCanonicalPubKey(<Buffer>chunks[1])
);
} }
check.toJSON = function () { return 'witnessPubKeyHash input' } check.toJSON = function() {
return 'witnessPubKeyHash input';
};

View file

@ -1,13 +1,13 @@
// OP_0 {pubKeyHash} // OP_0 {pubKeyHash}
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 | Array<number | Buffer>): boolean {
const buffer = bscript.compile(script) const buffer = bscript.compile(script);
return buffer.length === 22 && return buffer.length === 22 && buffer[0] === OPS.OP_0 && buffer[1] === 0x14;
buffer[0] === OPS.OP_0 &&
buffer[1] === 0x14
} }
check.toJSON = function () { return 'Witness pubKeyHash output' } check.toJSON = function() {
return 'Witness pubKeyHash output';
};

View file

@ -1,7 +1,4 @@
import * as input from './input' import * as input from './input';
import * as output from './output' import * as output from './output';
export { export { input, output };
input,
output,
}

View file

@ -1,36 +1,50 @@
// <scriptSig> {serialized scriptPubKey script} // <scriptSig> {serialized scriptPubKey script}
import * as bscript from '../../script' import * as bscript from '../../script';
const typeforce = require('typeforce') const typeforce = require('typeforce');
import * as p2ms from '../multisig' 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 (chunks: Array<Buffer>, allowIncomplete?: boolean): boolean { export function check(
typeforce(typeforce.Array, chunks) chunks: Array<Buffer>,
if (chunks.length < 1) return false allowIncomplete?: boolean,
): boolean {
typeforce(typeforce.Array, chunks);
if (chunks.length < 1) return false;
const witnessScript = chunks[chunks.length - 1] const witnessScript = chunks[chunks.length - 1];
if (!Buffer.isBuffer(witnessScript)) return false if (!Buffer.isBuffer(witnessScript)) return false;
const witnessScriptChunks = bscript.decompile(witnessScript) const witnessScriptChunks = bscript.decompile(witnessScript);
// is witnessScript a valid script? // is witnessScript a valid script?
if (!witnessScriptChunks || witnessScriptChunks.length === 0) return false if (!witnessScriptChunks || witnessScriptChunks.length === 0) return false;
const witnessRawScriptSig = bscript.compile(chunks.slice(0, -1)) const witnessRawScriptSig = bscript.compile(chunks.slice(0, -1));
// match types // match types
if (p2pkh.input.check(witnessRawScriptSig) && if (
p2pkh.output.check(witnessScriptChunks)) return true p2pkh.input.check(witnessRawScriptSig) &&
p2pkh.output.check(witnessScriptChunks)
)
return true;
if (p2ms.input.check(witnessRawScriptSig, allowIncomplete) && if (
p2ms.output.check(witnessScriptChunks)) return true p2ms.input.check(witnessRawScriptSig, allowIncomplete) &&
p2ms.output.check(witnessScriptChunks)
)
return true;
if (p2pk.input.check(witnessRawScriptSig) && if (
p2pk.output.check(witnessScriptChunks)) return true p2pk.input.check(witnessRawScriptSig) &&
p2pk.output.check(witnessScriptChunks)
)
return true;
return false return false;
} }
check.toJSON = function () { return 'witnessScriptHash input' } check.toJSON = function() {
return 'witnessScriptHash input';
};

View file

@ -1,13 +1,13 @@
// OP_0 {scriptHash} // OP_0 {scriptHash}
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 | Array<number | Buffer>): boolean {
const buffer = bscript.compile(script) const buffer = bscript.compile(script);
return buffer.length === 34 && return buffer.length === 34 && buffer[0] === OPS.OP_0 && buffer[1] === 0x20;
buffer[0] === OPS.OP_0 &&
buffer[1] === 0x20
} }
check.toJSON = function () { return 'Witness scriptHash output' } check.toJSON = function() {
return 'Witness scriptHash output';
};