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

tiddlybit

v0.0.6

Published

A tiddly JavaScript library for constructing, parsing and serializing Bitcoin scripts.

Downloads

6

Readme

TiddlyBit

A tiddly JavaScript library for constructing, parsing and serializing Bitcoin scripts.


When you need to construct and serialize a Bitcoin script for use in something like Money Button, you could just use bsv.js and add 336kb to your website payload... or you could use TiddlyBit which is 96.4% more tiddly!.

  • TiddlyBit parses and serializes Bitcoin scripts to and from Buffers, Typed Arrays, and hex or ASM encoded strings.
  • Weighing in at just 12kb minimised (4kb when gziped), TiddlyBit is a much leaner option for use on the Web.
  • TiddlyBit uses Buffers in Node.js, but in the browser uses native Typed Arrays which is much more performant than putting binary data in Objects.
  • Super simple, dev-friendly API.

Installation

When using NPM:

npm install tiddlybit
const {Script, OpCode} = require('tiddlybit')

Or using in the browser via CDN:

<script src="//unpkg.com/tiddlybit@latest/dist/tiddlybit.min.js"></script>
const {Script, OpCode} = TiddlyBit

Usage

Constructing a new script:

const {Script, OpCode} = require('tiddlybit')

const script = new Script([
  OpCode.OP_FALSE,
  OpCode.OP_RETURN,
  'hello',
  'world'
])

script.toASM()
// => '0 OP_RETURN 68656c6c6f 776f726c64'

script.toHex()
// => '006a0568656c6c6f05776f726c64'

Parsing a script:

const {Script} = require('tiddlybit')

const script = Script.fromHex('76a9146afc0d6bb578282ac0f6ad5c5af2294c1971210888ac')
// => Script {
//      chunks: [
//        <OpCode 118 OP_DUP>,
//        <OpCode 169 OP_HASH160>,
//        <Buffer 6a fc 0d 6b b5 78 28 2a c0 f6 ad 5c 5a f2 29 4c 19 71 21 08>,
//        <OpCode 136 OP_EQUALVERIFY>,
//        <OpCode 172 OP_CHECKSIG>
//      ]
//    }

The OpCode object has properties with cached instances for every valid code. If needed, new OpCode instances can be created using the contructor function:

const {OpCode} = require('tiddlybit')

OpCode.OP_RETURN
// => <OpCode 106 OP_RETURN>

// If needed you can find an OpCode by it's byte number
OpCode.byByte(106)
// => <OpCode 106 OP_RETURN>

// Alternatively you can initialise a new OpCode
new OpCode('OP_RETURN')
// => <OpCode 106 OP_RETURN>

TiddlyBit also exposes a binary helper for cross-platform binary operations. See the bops documentation for API details:

const {binary, Script, OpCode} = require('tiddlybit')

const buf = binary.create(4)
binary.writeUInt32LE(buf, 0x12345678, 0)

const script = new Script([
  OpCode.OP_RETURN,
  buf
])
// => Script {
//      chunks: [
//        <OpCode 106 OP_RETURN>,
//        <Buffer 78 56 34 12>
//      ]
//    }

API

Script class

new Script(array)

Creates a script instance from the given array of data chunks.

Script.fromASM(str)

Parses an ASM string and returns a script instance.

Script.fromBuffer(buf)

Parses a binary transaction and returns a script instance.

Script.fromHex(str)

Parses a hex encoded script and returns a script instance.

Script instance

Script#push(array)

Push a single or array of chunks onto the script.

Script#toASM()

Searializes the script into an ASM encoded string.

Script#toBuffer()

Searializes the script into a buffer.

Script#toHex()

Searializes the script into a hex encoded string.

OpCode class

new OpCode(string)

Creates an OpCode instance from the given string.

OpCode.byByte(str)

Find OpCode instance by byte number.

OpCode instance

OpCode#toBuffer()

Searializes the Op Code into a buffer.

License

MIT License.

© Copyright 2020 libitx.