nwc

package
v0.13.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2025 License: Unlicense Imports: 21 Imported by: 0

README

NWC Client

Nostr Wallet Connect (NIP-47) client implementation.

Usage

import "orly.dev/pkg/protocol/nwc"

// Create client from NWC connection URI
client, err := nwc.NewClient("nostr+walletconnect://...")
if err != nil {
    log.Fatal(err)
}

// Make requests
var info map[string]any
err = client.Request(ctx, "get_info", nil, &info)

var balance map[string]any
err = client.Request(ctx, "get_balance", nil, &balance)

var invoice map[string]any
params := map[string]any{"amount": 1000, "description": "test"}
err = client.Request(ctx, "make_invoice", params, &invoice)

Methods

  • get_info - Get wallet info
  • get_balance - Get wallet balance
  • make_invoice - Create invoice
  • lookup_invoice - Check invoice status
  • pay_invoice - Pay invoice

Payment Notifications

// Subscribe to payment notifications
err = client.SubscribeNotifications(ctx, func(notificationType string, notification map[string]any) error {
    if notificationType == "payment_received" {
        amount := notification["amount"].(float64)
        description := notification["description"].(string)
        // Process payment...
    }
    return nil
})

Features

  • NIP-44 encryption
  • Event signing
  • Relay communication
  • Payment notifications
  • Error handling

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(connectionURI string) (cl *Client, err error)

func (*Client) Request

func (cl *Client) Request(
	c context.Context, method string, params, result any,
) (err error)

func (*Client) SubscribeNotifications

func (cl *Client) SubscribeNotifications(
	c context.Context, handler NotificationHandler,
) (err error)

SubscribeNotifications subscribes to NWC notification events (kinds 23197/23196) and handles them with the provided callback. It maintains a persistent connection with auto-reconnection on disconnect.

type ConnectionParams

type ConnectionParams struct {
	// contains filtered or unexported fields
}

func ParseConnectionURI

func ParseConnectionURI(nwcUri string) (parts *ConnectionParams, err error)

func (*ConnectionParams) GetConversationKey

func (c *ConnectionParams) GetConversationKey() []byte

GetConversationKey returns the conversation key from the ConnectionParams.

func (*ConnectionParams) GetWalletPublicKey

func (c *ConnectionParams) GetWalletPublicKey() []byte

GetWalletPublicKey returns the wallet public key from the ConnectionParams.

type MockWalletService

type MockWalletService struct {
	// contains filtered or unexported fields
}

MockWalletService implements a mock NIP-47 wallet service for testing

func NewMockWalletService

func NewMockWalletService(
	relay string, initialBalance int64,
) (service *MockWalletService, err error)

NewMockWalletService creates a new mock wallet service

func (*MockWalletService) GetWalletPublicKey

func (m *MockWalletService) GetWalletPublicKey() []byte

GetWalletPublicKey returns the wallet's public key

func (*MockWalletService) SimulateIncomingPayment

func (m *MockWalletService) SimulateIncomingPayment(
	pubkey []byte, amount int64, description string,
) (err error)

SimulateIncomingPayment simulates an incoming payment for testing

func (*MockWalletService) Start

func (m *MockWalletService) Start() (err error)

Start begins the mock wallet service

func (*MockWalletService) Stop

func (m *MockWalletService) Stop()

Stop stops the mock wallet service

type NotificationHandler

type NotificationHandler func(
	notificationType string, notification map[string]any,
) error

NotificationHandler is a callback for handling NWC notifications

Source Files

  • client.go
  • mock_wallet_service.go
  • uri.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL