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

@smartledger/ordinals

v0.1.6

Published

1Sat Ordinals protocol in pure functions: envelope parsing, ordinal theory arithmetic, and BSV-20 / BSV-21 token rules

Readme

@smartledger/ordinals

The 1Sat Ordinals protocol as pure functions: envelope parsing, ordinal theory arithmetic, and BSV-20 / BSV-21 token rules.

No network, no database, no framework. That is the point — the same code backs an API, an indexer, a wallet, or a test.

npm install @smartledger/ordinals

Reading an inscription

import { inscriptionAt, parseEnvelopes } from '@smartledger/ordinals'

const insc = inscriptionAt(output.script, `${txid}_${vout}`)
insc.contentType   // 'image/png'
insc.content       // Buffer
insc.token         // BSV-20 / BSV-21 document, or null
insc.lock          // the locking script alone - toAddress works on it
insc.opReturn      // trailing OP_RETURN data, MAP tags decoded

lock is the locking script with both the envelope and any trailing OP_RETURN removed, because that is what a caller wants it for: deriving an address from a script with an OP_RETURN still attached simply fails.

Custom fields are warned about when they sit on an unrecognized even tag: the Ordinals spec says such an inscription must be treated as unbound, while an unknown odd tag is simply ignored. Parsers that do not check this - including this one, which still returns the field - give no hint that anything is wrong, so the warning is the only thing standing between a custom tag and an inscription that loses its location in someone else's indexer.

parseEnvelopes gives the full picture when you need it: every field/value pair (not just content-type), OP_1-OP_16 aliases normalised, repeated fields resolved last-wins with the repeats reported, multi-push bodies counted, and every envelope in the script — only the first of which can be an ordinal.

Token rules

import { detectToken } from '@smartledger/ordinals'

const token = detectToken({ body, contentType, outpoint })
token.standard    // 'BSV-20' (tick) | 'BSV-21' (id)
token.wellFormed  // the document is correctly shaped for its op
token.validated   // 'document' - see below

wellFormed is not valid. It says one document is correctly shaped; it says nothing about conservation, supply, or ticker priority, which are properties of a chain rather than of an output. notValidated names them so the difference cannot be missed.

Ordinal theory

The nth satoshi in is the nth satoshi out. These functions are that rule:

import { followForward, followBackward, outputAtOffset } from '@smartledger/ordinals'

followBackward(tx, vout, 0, inputValues)  // where did this satoshi come from
followForward(spendingTx, outpoint, 0, inputValues)  // where did it go
outputAtOffset(tx, offset)  // { vout, satoshis } or { burned: 'fee' }

Absolute satoshi offsets make the mapping an identity, so the same two functions trace an ordinal to its origin, follow it to its holder, and tell a transfer apart from a burn.

What is here

| | | | --- | --- | | parseEnvelopes, inscriptionAt, tokenAt, tokenOutputs | inscriptions | | detectToken, classifyToken, applyDeploy | BSV-20 / BSV-21 | | followForward, followBackward, outputAtOffset, inputAtOffset, inputOutpoint, inputSpending, outputOffset | ordinal theory | | FIELD_DEFS, resolveField, encodeValue, effectiveEncoding | envelope fields | | parseOutpoint, formatOutpoint, assertTxid | outpoints |

Built on @smartledger/bsv.

MIT.