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

@hlvuser/ability-lightning-invoice

v1.0.0

Published

Vincent ability to create Lightning Network invoices via NWC for HLV Protocol

Downloads

2

Readme

Lightning Invoice Creation Ability

Vincent ability to create Lightning Network invoices via NWC (Nostr Wallet Connect) for HLV Protocol.

Purpose

This ability is used in the HLV Protocol rebalancing flow:

  1. User clicks "Rebalance" with X% of their wBTC balance
  2. This ability creates a Lightning invoice for the equivalent amount in sats
  3. Returns payment hash which is used to create HTLC on Hedera
  4. Agent monitors for payment and captures preimage
  5. Preimage used to claim wBTC from HTLC

Flow

User Request → Create LN Invoice → Get Payment Hash → Create HTLC → Monitor Payment

Ability Parameters

{
  amountSat: number;       // Amount in satoshis
  description?: string;     // Optional description
  expirySec?: number;      // Expiry in seconds (default 24h)
  nwcUri: string;          // Nostr Wallet Connect URI
}

Response

{
  paymentRequest: string;   // BOLT11 invoice
  paymentHash: string;      // Payment hash (for HTLC)
  amountSat: number;        // Invoice amount
  description?: string;     // Invoice description
  expiresAt: number;        // Unix timestamp
}

Usage Example

import { getVincentAbilityClient } from '@lit-protocol/vincent-app-sdk/abilityClient';
import { bundledVincentAbility } from '@hlv/ability-lightning-invoice';

const abilityClient = getVincentAbilityClient({
  bundledVincentAbility,
  ethersSigner: yourEthersSigner,
});

// Precheck
const precheckResult = await abilityClient.precheck(
  {
    amountSat: 100000, // 100k sats
    description: 'HLV Protocol rebalance',
    expirySec: 86400, // 24 hours
    nwcUri: 'nostr+walletconnect://...',
  },
  {
    delegatorPkpEthAddress: userVincentWalletAddress,
  },
);

// Execute
if (precheckResult.success) {
  const result = await abilityClient.execute(
    {
      amountSat: 100000,
      description: 'HLV Protocol rebalance',
      nwcUri: 'nostr+walletconnect://...',
    },
    {
      delegatorPkpEthAddress: userVincentWalletAddress,
    },
  );

  if (result.success) {
    const { paymentHash, paymentRequest } = result.result;
    // Use paymentHash to create HTLC
    // paymentRequest is the invoice to present to user/agent
  }
}

Integration with HLV Protocol

1. Rebalance Button Click

// In hlv-frontend
const handleRebalance = async () => {
  // Get user's wBTC balance
  const wbtcBalance = await getWBTCBalance(userAddress);

  // Calculate 20% for rebalancing
  const rebalanceAmount = wbtcBalance * 0.2;

  // Convert to satoshis (assuming 1 wBTC = 100,000,000 sats)
  const amountSat = convertWBTCToSats(rebalanceAmount);

  // Create invoice via Vincent ability
  const invoiceResult = await createLightningInvoice({
    amountSat,
    description: `HLV Rebalance: ${rebalanceAmount} wBTC`,
    nwcUri: userNWCUri,
  });

  if (invoiceResult.success) {
    // Now create HTLC with the payment hash
    await createHTLC({
      paymentHash: invoiceResult.result.paymentHash,
      amount: rebalanceAmount,
      timelock: Date.now() + 86400000, // 24 hours
    });
  }
};

2. Backend Job Flow

// In hlv-backend job
async function executeRebalance(rebalanceRequest) {
  // Step 1: Create Lightning invoice
  const invoice = await lightningInvoiceAbility.execute({
    amountSat: rebalanceRequest.amountSat,
    nwcUri: rebalanceRequest.nwcUri,
  });

  // Step 2: Create HTLC on Hedera
  const htlc = await hederaHTLCAbility.execute({
    paymentHash: invoice.paymentHash,
    tokenAmount: rebalanceRequest.wbtcAmount,
    timelock: invoice.expiresAt,
  });

  // Step 3: Monitor for payment
  // (handled by separate monitoring job)

  return {
    invoiceRequest: invoice.paymentRequest,
    htlcContractId: htlc.contractId,
  };
}

NWC Integration

This ability uses Nostr Wallet Connect (NWC) to interact with Lightning wallets:

  • Alby: Most common NWC provider
  • LND with NWC bridge: For self-hosted nodes
  • Mutiny: Mobile wallet with NWC support

Getting NWC URI

  1. Open your NWC-compatible wallet (e.g., Alby)
  2. Go to Settings → Nostr Wallet Connect
  3. Create new connection with make_invoice permission
  4. Copy the nostr+walletconnect://... URI

Development

# Install dependencies
pnpm install

# Build
pnpm build

# Test
pnpm test

# Deploy to IPFS (requires PINATA_JWT)
pnpm deploy

Environment Variables

# For testing
TEST_NWC_URI=nostr+walletconnect://...
TEST_AMOUNT_SAT=1000

# For deployment
PINATA_JWT=your_pinata_jwt

TODO

  • [ ] Implement actual NWC connection
  • [ ] Add Nostr relay communication
  • [ ] Parse and validate BOLT11 invoices
  • [ ] Add retry logic for NWC commands
  • [ ] Implement proper error handling
  • [ ] Add invoice expiry monitoring
  • [ ] Support multiple NWC providers

Related

  • ability-hedera-htlc: Creates HTLCs on Hedera using the payment hash
  • ability-lightning-payment: Pays Lightning invoices (complementary)
  • hlv-starter-app: Frontend and backend that uses these abilities

License

MIT