Node Bitcoin Script
Node Bitcoin script parser
Installation
$ npm i bscript-parser --save
CLI Usage
General help:
$ bscript -h
Usage: bscript [options] [command]
Options:
-v, --version output the version number
-h, --help output usage information
Commands:
assemble [options] <raw-script>
disassemble [options] <asm>
getopcode <word>
getword <opcode>
isvalid <opcode-or-word>
isdisabled <opcode-or-word>
describe <opcode-or-word>
Help for a specific command, e.g.:
$ bscript assemble -h
Usage: assemble [options] <raw-script>
Options:
-l, --literal-style [style] Literal Style normal|brackets|prefixed|verbose (default: "normal")
-e, --encoding [encoding] Encoding ascii|base64|binary|hex|utf8 (default: "hex")
-h, --help output usage information
$ bscript assemble --literal-style normal 76a914306e2ea1eed91bf66dfe5d94f3957d4ba63bde8488acOP_DUP OP_HASH160 306e2ea1eed91bf66dfe5d94f3957d4ba63bde84 OP_EQUALVERIFY OP_CHECKSIG
Module Usage
You can parse raw hex string into an assembly string using:
> const BScript = undefined> BScript'OP_HASH160 c664139327b98043febeab6434eba89bb196d1af OP_EQUAL'
You can parse an assembly string into a raw script hex string using:
> BScript'a914c664139327b98043febeab6434eba89bb196d1af87'
The library also exposes several utility functions for getting information about bscript opcodes.
Conversion between opcodes and asm terms
> BScriptopcodes135> BScriptopcodes'OP_EQUAL'
Check if an opcode or asm term exists
> bscriptopcodestrue> bscriptopcodesfalse> bscriptopcodestrue> bscriptopcodesfalse
Check if an opcode or asm term is disabled
> bscriptopcodesfalse> bscriptopcodestrue> bscriptopcodesfalse> bscriptopcodestrue
Retrieve descriptive information for an opcode or asm term
Note: The data is taken from the bitcoin.it wiki.
> bscriptopcodes'Returns 1 if the inputs are exactly equal, 0 otherwise.'> bscriptopcodes'The input is hashed twice: first with SHA-256 and then with RIPEMD-160.'> bscriptopcodes'x1 x2'> bscriptopcodes'in'> bscriptopcodes'True / false'> bscriptopcodes'hash'
API Docs
You can view the the API docs for this project by running npm run docs:serve
in the project directory and then accessing
the documentation in your browser.
You can also access the pre-built API documentation as markdown here.
To prepare the pre-built api docs to be committed after a change is made to the code, run npm run docs:build
. The should be done before every release.