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 🙏

© 2026 – Pkg Stats / Ryan Hefner

txo_parser

v0.0.4

Published

Parser for TXO URI Specification (v0.2)

Readme

TXO URI Parser

A pure JavaScript ES module for parsing and formatting TXO URIs according to the TXO URI Specification v0.2.

Live Demo — Parse, build, manage vouchers, anchor state to Bitcoin. 7 interactive panes powered by LOSOS.

Installation

npm install txo_parser

For global installation (to use the CLI):

npm install -g txo_parser

Usage

As a Module

import { parseTxoUri, isValidTxoUri, formatTxoUri } from 'txo_parser'

// Parse a TXO URI
const uri =
  'txo:btc:4e9c1ef9ba5fa3b0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0:0?amount=0.75'
const parsed = parseTxoUri(uri)
console.log(parsed)
// Output:
// {
//   network: 'btc',
//   txid: '4e9c1ef9ba5fa3b0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0',
//   output: 0,
//   amount: 0.75
// }

// Parse legacy format
const legacyUri =
  'txo:btc:4e9c1ef9ba5fa3b0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0:0 0.75 Kx9'
const parsedLegacy = parseTxoUri(legacyUri)
console.log(parsedLegacy)
// Output:
// {
//   network: 'btc',
//   txid: '4e9c1ef9ba5fa3b0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0',
//   output: 0,
//   amount: 0.75,
//   privkey: 'Kx9'
// }

// Check if a URI is valid
console.log(isValidTxoUri(uri)) // true

// Format a JSON object into a TXO URI
const data = {
  network: 'btc',
  txid: '4e9c1ef9ba5fa3b0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0',
  output: 0,
  amount: 0.75,
  script_type: 'p2tr'
}
const formattedUri = formatTxoUri(data)
console.log(formattedUri)
// Output: txo:btc:4e9c1ef9ba5fa3b0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0:0?amount=0.75&script_type=p2tr

Using the CLI

The package includes a command-line tool that allows you to parse TXO URIs directly from the terminal:

# Parse a TXO URI and output the full JSON
txo-parser "txo:btc:4e9c1ef9ba5fa3b0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0:0?amount=0.75"

# Parse legacy format
txo-parser "txo:btc:4e9c1ef9ba5fa3b0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0:0 0.75 Kx9"

# Extract just the txid
txo-parser "txo:btc:4e9c1ef9ba5fa3b0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0:0" --txid

# Extract the network
txo-parser "txo:btc:4e9c1ef9ba5fa3b0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0:0" --network

# Get help
txo-parser --help

If you haven't installed the package globally, you can use npx:

npx txo-parser "txo:btc:4e9c1ef9ba5fa3b0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0:0"

Supported Formats

The parser supports two formats:

  1. Standard Format (as per specification):
    txo:<network>:<txid>:<output>?key=value&key=value...

  2. Legacy Format:
    txo:<network>:<txid>:<output> [amount] [privkey]

The legacy format supports up to two space-separated parameters after the basic structure:

  • First parameter is interpreted as the amount
  • Second parameter is interpreted as the private key

API

parseTxoUri(uri)

Parses a TXO URI string and returns a JSON object.

  • Parameters:
    • uri (string): The TXO URI to parse
  • Returns: Object with parsed components
  • Throws: Error if URI format is invalid

isValidTxoUri(uri)

Checks if a string is a valid TXO URI.

  • Parameters:
    • uri (string): The URI to validate
  • Returns: Boolean indicating validity

formatTxoUri(data)

Formats a JSON object into a TXO URI string.

  • Parameters:
    • data (object): The data to format (must include network, txid, and output)
  • Returns: Formatted TXO URI string (always in standard format)
  • Throws: Error if required fields are missing or invalid

Testing

Run tests with:

npm test

Using in Node.js Projects

If you're using this in a Node.js project, make sure your package.json includes:

{
  "type": "module"
}

Or when importing in a CommonJS project:

import { parseTxoUri } from 'txo_parser/index.js'

License

MIT