
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
bitcoin-script
Advanced tools
JavaScript implementation of Script, Bitcoin's scripting language, along with a Script Playground, deployed here. See my blog post for more.
The original ES6 source can be found on GitHub.
This package can be used to evaluate Bitcoin scripts as follows:
var evaluate = require('bitcoin-script').evaluate;
var script = 'OP_1 OP_VERIFY';
evaluate(script);
// => true
(Note: here, OP_VERIFY
could be excluded, as default behavior is to check for a 1 on the top of the stack if there's no terminating command in the script.)
Alternatively, you can use the lock-unlock paradigm, which concatenates the scripts before evaluating:
var unlock = require('bitcoin-script').unlock;
var scriptSig = 'OP_1';
var scriptPubKey = 'OP_VERIFY';
unlock(scriptSig, scriptPubKey);
// => true
If you'd like to enable disabled commands, you can do so by passing true
as the second argument to any of the exported functions. Here, we use the OP_MUL
command, which is typically disabled:
var evaluate = require('bitcoin-script').evaluate;
var script = 'OP_2 OP_3 OP_MUL OP_6 OP_EQUAL OP_VERIFY';
evaluate(script, /* enableDisabled */ true);
// => true
Further examples and tests are available in the GitHub repo.
(A longer explanation of Script and this implementation can be found in my blog post.)
Script programs are compiled to JavaScript using Jison, with behavior following the specification outlined on the Bitcoin Wiki. For those unfamiliar, Script is a simple, stack-based programming language used to validate transactions in the Bitcoin protocol.
When the parser runs over a Script program, it returns an object of the following form:
{
value: [value],
code: [code]
}
This allows for inspection into the compiled code (e.g., for use in the live editor), as well as the return value (true
or false
) of the Script.
As a user, you should only be using the functions exported in index.js
, which includes a parse
function that returns this (value, code)
pair.
Note that as this is an educational tool, the goal is not to create a full-fidelity re-implementation of Script, but rather, to focus on re-creating Script's core behavior. With that in mind, the implementation here differs from that described on the Wiki in a few ways. For example:
MIT.
FAQs
Compile Bitcoin Script to JavaScript.
The npm package bitcoin-script receives a total of 839 weekly downloads. As such, bitcoin-script popularity was classified as not popular.
We found that bitcoin-script demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.