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

ledgr

v0.0.14

Published

nostr ledgers

Readme



GitHub license npm npm Github Stars

Ledgr

Ledgr is a simple account management system that keeps track of balances for individual nostr public keys using Decentralized Identifiers (DIDs) in the format did:nostr:<pubkey>.

Specification

Data Model

Ledgr uses a structured JSON format that contains an array of entries, where each entry represents a balance for a specific DID:

{
  "entries": [
    {
      "type": "Entry",
      "url": "did:nostr:a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456",
      "amount": "100000"
    },
    {
      "type": "Entry",
      "url": "did:nostr:b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef12345678",
      "amount": "120000"
    }
  ]
}

Note: By default, the ledgr is stored in a file called webledger.json.

Entry Structure

Each entry in the ledger contains:

  • type: Always set to "Entry" to identify the record type
  • url: The DID identifier in the format did:nostr:<pubkey> (where pubkey is 64-character lowercase hex)
  • amount: The balance amount as a string (in satoshis)

Functions

Ledger offers the following functions for working with balances of DIDs:

  • deposit: Deposits satoshis to a DID.
  • withdraw: Withdraws satoshis from a DID.
  • transfer: Transfers satoshis from one DID to another.

Guide

Deposit

To deposit satoshis to a DID, use the deposit function.

deposit(did, amount)
  • did: The DID identifier to which the satoshis should be deposited (format: did:nostr:<pubkey>).
  • amount: The number of satoshis you want to deposit.

Withdraw

To withdraw satoshis from a DID, use the withdraw function.

withdraw(did, amount)
  • did: The DID identifier from which the satoshis should be withdrawn (format: did:nostr:<pubkey>).
  • amount: The number of satoshis you want to withdraw.

Transfer

To transfer satoshis from one DID to another, use the transfer function.

transfer(from_did, to_did, amount)
  • from_did: The DID identifier from which the satoshis should be transferred (format: did:nostr:<pubkey>).
  • to_did: The DID identifier to which the satoshis should be transferred (format: did:nostr:<pubkey>).
  • amount: The number of satoshis you want to transfer.

Usage Example

JavaScript

import Ledgr from 'ledgr';

// Create a new Ledgr instance (uses default webledger.json)
const ledgr = new Ledgr();

// Or specify a custom file path
const customLedgr = new Ledgr('/path/to/my-ledger.json');

// Deposit 100 satoshis to a DID
ledgr.deposit('did:nostr:a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456', 100);

// Withdraw 50 satoshis from a DID
ledgr.withdraw('did:nostr:a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456', 50);

// Transfer 25 satoshis from one DID to another
ledgr.transfer('did:nostr:a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456', 'did:nostr:b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef12345678', 25);

// Get balance for a specific DID
const balance = ledgr.getBalance('did:nostr:a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456');
console.log(`Balance: ${balance}`);

// Print all balances (backward compatibility)
console.log(ledgr.balances);

CLI Usage

The CLI tool provides convenient commands for managing the ledger:

# Basic usage (uses default webledger.json)
ledgr deposit did:nostr:a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456 100
ledgr withdraw did:nostr:a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456 50
ledgr transfer did:nostr:a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456 did:nostr:b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef12345678 25
ledgr balance did:nostr:a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456
ledgr list
ledgr clean

# Using a custom file path
ledgr -f /path/to/my-ledger.json deposit did:nostr:a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456 100
ledgr --file ./ledgers/company.json list
ledgr -f ~/documents/personal-ledger.json balance did:nostr:a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456

# All commands support the file option
ledgr -f custom.json clean

This way, you can use Ledgr to manage the balances of individual DIDs and perform various operations such as deposits, withdrawals, and transfers of satoshis using the decentralized identifier format.