diff --git a/src/classify.js b/src/classify.js index 0aec5c4..7d8e57d 100644 --- a/src/classify.js +++ b/src/classify.js @@ -6,9 +6,9 @@ const nullData = require("./templates/nulldata"); const pubKey = require("./templates/pubkey"); const pubKeyHash = require("./templates/pubkeyhash"); const scriptHash = require("./templates/scripthash"); +const witnessCommitment = require("./templates/witnesscommitment"); const witnessPubKeyHash = require("./templates/witnesspubkeyhash"); const witnessScriptHash = require("./templates/witnessscripthash"); -const witnessCommitment = require("./templates/witnesscommitment"); const types = { P2MS: 'multisig', NONSTANDARD: 'nonstandard', diff --git a/ts_src/classify.ts b/ts_src/classify.ts index 0de93f9..a7ec68c 100644 --- a/ts_src/classify.ts +++ b/ts_src/classify.ts @@ -4,20 +4,20 @@ import * as nullData from './templates/nulldata'; import * as pubKey from './templates/pubkey'; import * as pubKeyHash from './templates/pubkeyhash'; import * as scriptHash from './templates/scripthash'; +import * as witnessCommitment from './templates/witnesscommitment'; import * as witnessPubKeyHash from './templates/witnesspubkeyhash'; import * as witnessScriptHash from './templates/witnessscripthash'; -import * as witnessCommitment from './templates/witnesscommitment'; const types = { - P2MS: 'multisig', - NONSTANDARD: 'nonstandard', - NULLDATA: 'nulldata', - P2PK: 'pubkey', - P2PKH: 'pubkeyhash', - P2SH: 'scripthash', - P2WPKH: 'witnesspubkeyhash', - P2WSH: 'witnessscripthash', - WITNESS_COMMITMENT: 'witnesscommitment', + P2MS: 'multisig' as string, + NONSTANDARD: 'nonstandard' as string, + NULLDATA: 'nulldata' as string, + P2PK: 'pubkey' as string, + P2PKH: 'pubkeyhash' as string, + P2SH: 'scripthash' as string, + P2WPKH: 'witnesspubkeyhash' as string, + P2WSH: 'witnessscripthash' as string, + WITNESS_COMMITMENT: 'witnesscommitment' as string, }; function classifyOutput(script: Buffer): string { @@ -51,16 +51,13 @@ function classifyInput(script: Buffer, allowIncomplete: boolean): string { return types.NONSTANDARD; } -function classifyWitness( - script: Array, - allowIncomplete: boolean, -): string { +function classifyWitness(script: Buffer[], allowIncomplete: boolean): string { // XXX: optimization, below functions .decompile before use const chunks = decompile(script); if (!chunks) throw new TypeError('Invalid script'); if (witnessPubKeyHash.input.check(chunks)) return types.P2WPKH; - if (witnessScriptHash.input.check(>chunks, allowIncomplete)) + if (witnessScriptHash.input.check(chunks as Buffer[], allowIncomplete)) return types.P2WSH; return types.NONSTANDARD; diff --git a/types/classify.d.ts b/types/classify.d.ts index b394c71..67f913b 100644 --- a/types/classify.d.ts +++ b/types/classify.d.ts @@ -12,5 +12,5 @@ declare const types: { }; declare function classifyOutput(script: Buffer): string; declare function classifyInput(script: Buffer, allowIncomplete: boolean): string; -declare function classifyWitness(script: Array, allowIncomplete: boolean): string; +declare function classifyWitness(script: Buffer[], allowIncomplete: boolean): string; export { classifyInput as input, classifyOutput as output, classifyWitness as witness, types, };