You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.5 KiB
71 lines
2.5 KiB
6 years ago
|
import { decompile } from './script'
|
||
|
import * as multisig from './templates/multisig'
|
||
|
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 witnessPubKeyHash from './templates/witnesspubkeyhash'
|
||
|
import * as witnessScriptHash from './templates/witnessscripthash'
|
||
|
import * as witnessCommitment from './templates/witnesscommitment'
|
||
8 years ago
|
|
||
7 years ago
|
const types = {
|
||
6 years ago
|
P2MS: <string> 'multisig',
|
||
|
NONSTANDARD: <string> 'nonstandard',
|
||
|
NULLDATA: <string> 'nulldata',
|
||
|
P2PK: <string> 'pubkey',
|
||
|
P2PKH: <string> 'pubkeyhash',
|
||
|
P2SH: <string> 'scripthash',
|
||
|
P2WPKH: <string> 'witnesspubkeyhash',
|
||
|
P2WSH: <string> 'witnessscripthash',
|
||
|
WITNESS_COMMITMENT: <string> 'witnesscommitment'
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
6 years ago
|
function classifyOutput (script: Buffer): string {
|
||
8 years ago
|
if (witnessPubKeyHash.output.check(script)) return types.P2WPKH
|
||
|
if (witnessScriptHash.output.check(script)) return types.P2WSH
|
||
|
if (pubKeyHash.output.check(script)) return types.P2PKH
|
||
|
if (scriptHash.output.check(script)) return types.P2SH
|
||
8 years ago
|
|
||
|
// XXX: optimization, below functions .decompile before use
|
||
7 years ago
|
const chunks = decompile(script)
|
||
7 years ago
|
if (!chunks) throw new TypeError('Invalid script')
|
||
|
|
||
6 years ago
|
if (multisig.output.check(chunks)) return types.P2MS
|
||
8 years ago
|
if (pubKey.output.check(chunks)) return types.P2PK
|
||
8 years ago
|
if (witnessCommitment.output.check(chunks)) return types.WITNESS_COMMITMENT
|
||
8 years ago
|
if (nullData.output.check(chunks)) return types.NULLDATA
|
||
8 years ago
|
|
||
8 years ago
|
return types.NONSTANDARD
|
||
8 years ago
|
}
|
||
|
|
||
6 years ago
|
function classifyInput (script: Buffer, allowIncomplete: boolean): string {
|
||
8 years ago
|
// XXX: optimization, below functions .decompile before use
|
||
7 years ago
|
const chunks = decompile(script)
|
||
7 years ago
|
if (!chunks) throw new TypeError('Invalid script')
|
||
8 years ago
|
|
||
8 years ago
|
if (pubKeyHash.input.check(chunks)) return types.P2PKH
|
||
|
if (scriptHash.input.check(chunks, allowIncomplete)) return types.P2SH
|
||
6 years ago
|
if (multisig.input.check(chunks, allowIncomplete)) return types.P2MS
|
||
8 years ago
|
if (pubKey.input.check(chunks)) return types.P2PK
|
||
8 years ago
|
|
||
8 years ago
|
return types.NONSTANDARD
|
||
8 years ago
|
}
|
||
|
|
||
6 years ago
|
function classifyWitness (script: Array<Buffer>, allowIncomplete: boolean): string {
|
||
8 years ago
|
// XXX: optimization, below functions .decompile before use
|
||
7 years ago
|
const chunks = decompile(script)
|
||
7 years ago
|
if (!chunks) throw new TypeError('Invalid script')
|
||
8 years ago
|
|
||
8 years ago
|
if (witnessPubKeyHash.input.check(chunks)) return types.P2WPKH
|
||
6 years ago
|
if (witnessScriptHash.input.check(<Array<Buffer>>chunks, allowIncomplete)) return types.P2WSH
|
||
8 years ago
|
|
||
|
return types.NONSTANDARD
|
||
8 years ago
|
}
|
||
|
|
||
6 years ago
|
export {
|
||
|
classifyInput as input,
|
||
|
classifyOutput as output,
|
||
|
classifyWitness as witness,
|
||
|
types,
|
||
8 years ago
|
}
|