npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bscript-assembler

v0.1.3

Published

Node Bitcoin Script Parser

Downloads

6

Readme

Node Bitcoin Script

NPM Build Status

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 = require('bscript-parser')
undefined
> BScript.rawToAsm('a914c664139327b98043febeab6434eba89bb196d1af87', 'hex')
'OP_HASH160 c664139327b98043febeab6434eba89bb196d1af OP_EQUAL'

You can parse an assembly string into a raw script hex string using:

> BScript.asmToRaw('OP_HASH160 c664139327b98043febeab6434eba89bb196d1af OP_EQUAL', 'hex')
'a914c664139327b98043febeab6434eba89bb196d1af87'

The library also exposes several utility functions for getting information about bscript opcodes.

Conversion between opcodes and asm terms

> BScript.opcodes.opcodeForWord('OP_EQUAL')
135
> BScript.opcodes.wordForOpcode(135)
'OP_EQUAL'

Check if an opcode or asm term exists

> bscript.opcodes.opcodeIsValid(135)
true
> bscript.opcodes.opcodeIsValid(256)
false
> bscript.opcodes.wordIsValid('OP_EQUAL')
true
> bscript.opcodes.wordIsValid('OP_CLONE')
false

Check if an opcode or asm term is disabled

> bscript.opcodes.opcodeIsDisabled(135)
false
> bscript.opcodes.opcodeIsDisabled(126)
true
> bscript.opcodes.wordIsDisabled('OP_EQUAL')
false
> bscript.opcodes.wordIsDisabled('OP_CAT')
true

Retrieve descriptive information for an opcode or asm term

Note: The data is taken from the bitcoin.it wiki.

> bscript.opcodes.descriptionForOpcode(135)
'Returns 1 if the inputs are exactly equal, 0 otherwise.'
> bscript.opcodes.descriptionForWord('OP_HASH160')
'The input is hashed twice: first with SHA-256 and then with RIPEMD-160.'
> bscript.opcodes.inputDescriptionForOpcode(135)
'x1 x2'
> bscript.opcodes.inputDescriptionForWord('OP_HASH160')
'in'
> bscript.opcodes.outputDescriptionForOpcode(135)
'True / false'
> bscript.opcodes.outputDescriptionForWord('OP_HASH160')
'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.