Commit js, ts, and definitions in separate folders

This commit is contained in:
junderw 2019-01-04 18:33:02 +09:00
parent e7ac2b9a4e
commit bc28949056
No known key found for this signature in database
GPG key ID: B256185D3A971908
148 changed files with 3850 additions and 39 deletions
ts_src/templates/scripthash

View file

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

View file

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

View file

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