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 🙏

© 2025 – Pkg Stats / Ryan Hefner

charms-js

v3.3.1

Published

TypeScript SDK for decoding Bitcoin transactions containing Charms data

Downloads

268

Readme

Charms JS

TypeScript SDK for decoding Bitcoin transactions containing Charms data.

Installation

npm install charms-js

Usage

Browser (Automatic WASM initialization)

import { extractCharmsForWallet } from 'charms-js';

// Simple usage - WASM auto-initializes
const charms = await extractCharmsForWallet(
  txHex, 
  txId, 
  walletOutpoints, 
  'testnet4'
);

console.log('Charms found:', charms);

Requirements for Browser:

  • Copy charms_lib_bg.wasm to your public/ directory
  • The library will automatically load and initialize the WASM module

Node.js (Manual WASM initialization)

import { initializeWasm, extractCharmsForWallet } from 'charms-js/dist/node';

// Manual WASM initialization required
const wasmBindings = await import('charms-js/dist/wasm/charms_lib_bg.js');
const fs = require('fs');
const wasmBuffer = fs.readFileSync('path/to/charms_lib_bg.wasm');

const wasmModule = await WebAssembly.instantiate(wasmBuffer, {
  './charms_lib_bg.js': wasmBindings
});

wasmBindings.__wbg_set_wasm(wasmModule.instance.exports);
initializeWasm(wasmBindings);

// Now you can use the library
const charms = await extractCharmsForWallet(txHex, txId, walletOutpoints, 'testnet4');

File Structure

src/
├── index.ts          # Browser entry point (auto-init WASM)
├── node.ts           # Node.js entry point (manual init)
├── browser.ts        # Browser-specific WASM auto-initialization
├── wasm-integration.ts # Core WASM integration logic
├── wallet-adapter.ts # Wallet filtering utilities
└── wasm/            # WASM binaries and bindings
    ├── charms_lib_bg.wasm
    └── charms_lib_bg.js

API Reference

extractCharmsForWallet(txHex, txId, walletOutpoints, network?)

Extracts charms from a transaction, filtered by wallet ownership.

Parameters:

  • txHex: Transaction hex string
  • txId: Transaction ID
  • walletOutpoints: Set of wallet-owned outpoints (txid:vout)
  • network: 'mainnet' or 'testnet4' (default: 'testnet4')

Returns: Promise<CharmObj[]>

Browser-only functions

  • isWasmReady(): Check if WASM is initialized

Types

interface CharmObj {
  appId: string;
  amount: number;           // Amount in satoshis
  version: number;
  metadata: {
    ticker?: string;
    name?: string;
    description?: string;
    image?: string;
    image_hash?: string;
    url?: string;
  };
  app: Record<string, any>;
  outputIndex: number;      // Zero-based output index in the transaction
  txid: string;             // Transaction ID in display format (little-endian, reversed bytes)
  address: string;          // Bitcoin address for this output (P2PKH, P2SH, P2WPKH, P2WSH, or P2TR)
}

Important Notes

Transaction ID Format: The txid field is returned in display format (little-endian, reversed bytes), which matches the format used by block explorers like mempool.space. This is the standard format for displaying transaction IDs to users.

Output Index: The outputIndex corresponds to the position of this charm's output in the transaction, starting from 0. Use this with txid to uniquely identify the UTXO: ${txid}:${outputIndex}

Address: The address field contains the Bitcoin address that controls this output. This is extracted directly from the output's scriptPubKey and supports all standard address types including Taproot (P2TR).

Migration from v3.0.x

Browser users: Replace manual WASM initialization with direct imports:

// OLD (manual)
await ensureWasmInitialized();
const charms = await extractCharmsForWallet(...);

// NEW (automatic)
import { extractCharmsForWallet } from 'charms-js';
const charms = await extractCharmsForWallet(...);
  • The WASM extraction operates on txHex. The txid included in CharmObj is provided for identification and wallet filtering convenience.

License

MIT