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

bitcoin-script-eval

v0.1.1

Published

Evaluates Bitcoin Scripts, according to the specification of Bitcoin SV.

Downloads

4

Readme

Bitcoin Script Evaluator

Evaluates Bitcoin Scripts, according to the specification of Bitcoin SV.

Install

npm i --save bitcoin-script-eval

Usage

The standard usage is to evaluate a script and examine its result.

const bitcoinScriptEval = require("bitcoin-script-eval");

bitcoinScriptEval("ff f1 OP_CAT 01 OP_SPLIT", "asm").then((context) => {
  context.stack; // a Buffer array with values [ ff, f1 ]
  context.altStack; // a Buffer array with all values in the altStack at the end of the script
  context.opReturn; // a Buffer array with all values following an OP_RETURN that got executed
  context.ended; // boolean that gets set to TRUE once the evaluation ends
  context.interrupted; // boolean that gets set to TRUE if the evaluation ended with an interruption.
  context.endedWithOpReturn; // boolean that gets set to TRUE if the evaluation ended with an OP_RETURN.
  context.endMessage; // string explaining what interrupted the script (Error message or "OP_RETURN").
  context.done; // boolean that gets set to TRUE once the evaluation ends without interruption
  context.blocks; // details about unfinished OP_IF blocks
});

Execute Step by Step

An alternative usage is to split the execution into chunks. This makes it possible to evaluate the state of the script after each chunk.

To continue the evaluation from where the previous script ended, simply pass on the exact same context object to the evaluation.

const bitcoinScriptEval = require("bitcoinScriptEval");
const context1 = await bitcoinScriptEval("ff f1", "asm"); // stack is [ff, f1]
const context2 = await bitcoinScriptEval("OP_CAT", "asm", context1); // stack is [fff1]
const context3 = await bitcoinScriptEval("01 OP_SPLIT", "asm", context2); // stack is [ff, f1]

Here are some rules about splitting scripts into chunks:

  • If a previous chunk put data in the Stack or AltStack, then this data will still be present for the next chunk of code
  • If a previous chunk had unfinished OP_IF blocks, then the current chunk will keep looking for these blocks to close
  • If a previous chunk did an OP_RETURN, then the next chunk will simply be considered data in the OP_RETURN
  • If a previous chunk had an interruption error, then the next chunk won't actually get executed

Signatures don't work yet

Some parts of the library are not complete, like signature validation.

As a workaround, set:

context.sigsAlwaysPass = true;

This will make all Sig opcodes consume the same stack variables, but without checking if the sigs are valid.

sigsAlwaysPass is FALSE by default.

Disabled OpCodes

By default, this tool supports disabled opcodes. If you want it to fail on disabled opcodes instead, set:

context.failOnDisabled = true;

Disclaimer

This code is provided AS-IS, without any warranty. See the license.