Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@nostr-dev-kit/ndk-wallet

nostr-dev-kit3.4kMIT0.7.1TypeScript support: included

NDK Wallet

nostr, cashu, ecash

readme

@nostr-dev-kit/ndk-wallet

A wallet toolkit for the Nostr ecosystem, providing implementations for NIP-47 (NWC), NIP-57 (Zaps), and NIP-60 (Cashu eCash) wallets.

Overview

The ndk-wallet package extends NDK with wallet capabilities, allowing applications to manage and interact with various wallet types in the Nostr ecosystem. Key features include:

  • NIP-60 Wallet: Implementation of Cashu eCash wallets for Nostr
  • Nutzap Monitor: Automated monitoring and redemption of Nutzaps (NIP-60 zaps)
  • NWC Client: For interacting with wallets via Nostr Wallet Connect (NIP-47)
  • Zap Support: For sending and receiving Lightning zaps (NIP-57)

Components

Wallet Base (NDKWallet)

The NDKWallet interface serves as the foundation for all wallet implementations, providing a common API for:

  • Retrieving balances
  • Sending and receiving payments
  • Interacting with wallet events
  • Managing wallet status

Cashu Wallet (NDKCashuWallet)

The NDKCashuWallet implements the NIP-60 specification, providing a fully-featured Cashu eCash wallet:

  • Token management and validation
  • Sending and receiving tokens via nutzaps
  • Mint interaction and token issuance
  • Proofs handling and validation
  • Backup and restore functionality
import { NDKCashuWallet } from "@nostr-dev-kit/ndk-wallet";

// Create a Cashu wallet
const wallet = new NDKCashuWallet(ndk);

// Add mints
wallet.addMint("https://mint.example.com");

// Get wallet balance
const balance = await wallet.getBalance();

Nutzap Monitor (NDKNutzapMonitor)

The NDKNutzapMonitor automatically monitors and processes nutzaps (NIP-60 zaps) for a user:

  • Listens for incoming nutzaps
  • Manages nutzap states
  • Redeems tokens when appropriate private keys are available
  • Persists nutzap states across sessions using a customizable store
import { NDKNutzapMonitor } from "@nostr-dev-kit/ndk-wallet";

// Create a monitor
const monitor = new NDKNutzapMonitor(ndk, user, { mintList, store });

// Set wallet and start monitoring
monitor.wallet = myCashuWallet;
await monitor.start();

For detailed information on using the Nutzap Monitor, see Nutzap Monitor Documentation.

NWC Client (NDKWalletNWC)

The NDKWalletNWC implements the NIP-47 specification for Nostr Wallet Connect:

  • Connect to NWC-compatible wallets
  • Send payment requests
  • Query wallet information
  • Handle payment responses
import { NDKWalletNWC } from "@nostr-dev-kit/ndk-wallet";

// Create an NWC wallet
const wallet = new NDKWalletNWC(ndk, nwcConnectionInfo);

// Pay an invoice
await wallet.pay({ invoice: "lnbc..." });

State Management

The wallet components use state management patterns to track the status of operations:

  • NDKCashuWallet tracks token states, mint connections, and wallet status
  • NDKNutzapMonitor implements a state machine for tracking nutzap processing
  • State stores provide persistent storage options

Events

All wallet components emit events that applications can listen to:

  • Balance changes
  • Payment events
  • State transitions
  • Errors and warnings
wallet.on("balance_changed", (newBalance) => {
    console.log(`New balance: ${newBalance}`);
});

Documentation

For more detailed documentation on specific components:

Installation

npm install @nostr-dev-kit/ndk-wallet

Requirements

  • @nostr-dev-kit/ndk: Peer dependency
  • Modern browser or Node.js environment

License

MIT

changelog

@nostr-dev-kit/ndk-cache-redis

0.7.0

Minor Changes

  • Add cashu mint list support for nutzap reception

    • Add mintList getter and fetchMintList method to NDKCashuWallet
    • Implement automatic mint list fetching during wallet initialization
    • Support NIP-61 nutzap reception configuration through mint lists
    • Add comprehensive test coverage for mint list functionality
    • Add subId parameters for better subscription tracking

      This enables wallets to properly configure nutzap reception by fetching and exposing their published mint lists (kind:10019 events), supporting the NIP-61 specification for enhanced cashu token interoperability.

Patch Changes

0.6.3

Patch Changes

  • 96341c3: Remove old NIP-60 migration code and legacy wallet kind 37375

    • Removed getOldWallets function and migrateCashuWallet from ndk-wallet
    • Removed LegacyCashuWallet = 37375 kind definition from ndk-core
    • Cleaned up all references to the legacy migration code
  • Updated dependencies [2886111]

  • Updated dependencies [96341c3]

0.6.2

Patch Changes

  • bump

0.6.1

Patch Changes

  • make wallet.start() wait until the wallet is ready

0.6.0

Minor Changes

  • bump

0.5.14

Patch Changes

  • bump

0.5.11

Patch Changes

0.5.10

Patch Changes

0.5.9

Patch Changes

0.5.8

Patch Changes

0.5.7

Patch Changes

0.5.6

Patch Changes

  • fix release

0.5.5

Patch Changes

0.5.4

Patch Changes

  • bump

0.5.3

Patch Changes

0.5.2

Patch Changes

  • c83166a: bump
  • import changes
  • Updated dependencies [c83166a]
  • Updated dependencies [5ab19ef]
  • Updated dependencies [6e16e06]
  • Updated dependencies
  • Updated dependencies [5ab19ef]

0.5.0

Minor Changes

  • BREAKING: move wallet balance to be a getter since it sets a more natural expectation of what the function does
  • Bug fix: NWC nutzaps always validate that the p2pk is properly padded

Patch Changes

  • implement mint get/set interfaces at the NDKWallet level

0.4.3

Patch Changes

0.4.2

Patch Changes

  • cca3357: move NDKWalletChange from ndk-wallet to NDKCashuWalletTx in ndk
  • Updated dependencies [3ea9695]
  • Updated dependencies [cca3357]
  • Updated dependencies [1235f69]

0.4.1

Patch Changes

  • Updated dependencies [f255a07]
  • Updated dependencies [f255a07]
  • Updated dependencies [2171140]
  • Updated dependencies [72c8492]
  • Updated dependencies [72c8492]

0.4.0

Minor Changes

  • Update to new NIP-60 and NIP-61 implementations

Patch Changes

0.3.17

Patch Changes

0.3.16

Patch Changes

  • 689305c: NWC support
  • Updated dependencies [35987be]
  • Updated dependencies [689305c]
  • Updated dependencies [35987be]
  • Updated dependencies [35987be]
  • Updated dependencies
  • Updated dependencies [4ed75a6]

0.3.15

Patch Changes

0.3.14

Patch Changes

0.3.13

Patch Changes

0.3.12

Patch Changes

0.3.11

Patch Changes

  • 0bdffa7: if we run into duplicate proofs throughout the same or different tokens, clean up when we roll them into a new token event
  • 0bdffa7: be more tolerant of incorrect nip04 encryption
  • apply orphan tokens to the default wallet
  • Updated dependencies [0fc66c5]

0.3.10

Patch Changes

  • bump

0.3.9

Patch Changes

  • nip44 decrypt wallet change events

0.3.8

Patch Changes

  • avoid duplicating proofs when they existed previously in different tokens

0.3.7

Patch Changes

  • fix issue were two tokens are being created when redeeming cashu

0.3.6

Patch Changes

  • bump

0.3.5

Patch Changes

  • receive cashu

0.3.4

Patch Changes

  • 0191977: provide a way to create nuts of specific denomincation(s)

0.3.3

Patch Changes

0.3.2

Patch Changes

  • bump

0.3.1

Patch Changes

  • publish wallet change events

0.3.0

Minor Changes

  • update to cashuts 1.1.0

Patch Changes

  • Updated dependencies [d6cfa8a]
  • Updated dependencies [d6cfa8a]
  • Updated dependencies [d6cfa8a]
  • Updated dependencies [722345b]

0.2.0

Minor Changes

  • Zap improvements

Patch Changes

  • Updated dependencies [ec83ddc]
  • Updated dependencies [18c55bb]
  • Updated dependencies
  • Updated dependencies [18c55bb]
  • Updated dependencies
  • Updated dependencies
  • Updated dependencies [3029124]

2.1.16

Patch Changes

2.1.15

Patch Changes

2.1.14

Patch Changes

2.1.13

Patch Changes

2.1.12

Patch Changes

  • Updated dependencies [91d873c]
  • Updated dependencies [6fd9ddc]
  • Updated dependencies [0b8f331]
  • Updated dependencies
  • Updated dependencies [f2898ad]
  • Updated dependencies [9b92cd9]
  • Updated dependencies
  • Updated dependencies [6814f0c]
  • Updated dependencies [89b5b3f]
  • Updated dependencies [9b92cd9]
  • Updated dependencies [27b10cc]
  • Updated dependencies
  • Updated dependencies
  • Updated dependencies [ed7cdc4]

2.1.11

Patch Changes

2.1.10

Patch Changes

2.1.9

Patch Changes

2.1.8

Patch Changes

  • Updated dependencies
  • Updated dependencies [c2db3c1]
  • Updated dependencies
  • Updated dependencies [c2db3c1]
  • Updated dependencies [c2db3c1]

2.1.7

Patch Changes

2.1.6

Patch Changes

2.1.5

Patch Changes

  • Updated dependencies [111c1ea]
  • Updated dependencies [5c0ae51]
  • Updated dependencies [6f5ea49]
  • Updated dependencies [3738d39]
  • Updated dependencies [d22239a]

2.1.4

Patch Changes

2.1.3

Patch Changes

2.1.2

Patch Changes

2.1.1

Patch Changes

2.1.0

Minor Changes

  • 06c83ea: Aggressively cache all filters and their responses so the same filter can hit the cache

Patch Changes

  • Updated dependencies [54cec78]
  • Updated dependencies [ef61d83]
  • Updated dependencies [98b77dd]
  • Updated dependencies [46b0c77]
  • Updated dependencies [082e243]

2.0.11

Patch Changes

2.0.10

Patch Changes

2.0.9

Patch Changes

2.0.8

Patch Changes

2.0.7

Patch Changes

2.0.6

Patch Changes

2.0.5

Patch Changes

2.0.5

Patch Changes

2.0.4

Patch Changes

2.0.3

Patch Changes

2.0.2

Patch Changes

1.8.7

Patch Changes

1.8.6

Patch Changes

1.8.5

Patch Changes

1.8.4

Patch Changes

1.8.3

Patch Changes

1.8.2

Patch Changes

1.8.1

Patch Changes

  • Updated dependencies [88df10a]
  • Updated dependencies [c225094]
  • Updated dependencies [cf4a648]
  • Updated dependencies [3946078]
  • Updated dependencies [3440768]