nwc

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2025 License: Unlicense Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CancelHoldInvoice    = Capability("cancel_hold_invoice")
	CreateConnection     = Capability("create_connection")
	GetBalance           = Capability("get_balance")
	GetBudget            = Capability("get_budget")
	GetInfo              = Capability("get_info")
	GetWalletServiceInfo = Capability("get_wallet_service_info")
	ListTransactions     = Capability("list_transactions")
	LookupInvoice        = Capability("lookup_invoice")
	MakeHoldInvoice      = Capability("make_hold_invoice")
	MakeInvoice          = Capability("make_invoice")
	MultiPayInvoice      = Capability("multi_pay_invoice")
	MultiPayKeysend      = Capability("multi_pay_keysend")
	PayInvoice           = Capability("pay_invoice")
	PayKeysend           = Capability("pay_keysend")
	SettleHoldInvoice    = Capability("settle_hold_invoice")
	SignMessage          = Capability("sign_message")
)
View Source
var (
	EncryptionTag = []byte("encryption")
	Nip04         = EncryptionType("nip04")
	Nip44V2       = EncryptionType("nip44_v2")
)
View Source
var (
	NotificationTag     = []byte("notification")
	PaymentReceived     = NotificationType("payment_received")
	PaymentSent         = NotificationType("payment_sent")
	HoldInvoiceAccepted = NotificationType("hold_invoice_accepted")
)

Functions

This section is empty.

Types

type CancelHoldInvoiceParams added in v0.5.0

type CancelHoldInvoiceParams struct {
	PaymentHash string `json:"payment_hash"`
}

type Capability

type Capability []byte

Capability represents a NIP-47 method

type Client

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

func NewClient added in v0.4.15

func NewClient(c context.T, connectionURI string) (cl *Client, err error)

func (*Client) CancelHoldInvoice added in v0.5.0

func (cl *Client) CancelHoldInvoice(
	c context.T, chi *CancelHoldInvoiceParams, noUnmarshal bool,
) (raw []byte, err error)

func (*Client) CreateConnection added in v0.5.0

func (cl *Client) CreateConnection(
	c context.T, cc *CreateConnectionParams, noUnmarshal bool,
) (raw []byte, err error)

func (*Client) GetBalance

func (cl *Client) GetBalance(c context.T, noUnmarshal bool) (
	gb *GetBalanceResult, raw []byte, err error,
)

func (*Client) GetBudget

func (cl *Client) GetBudget(c context.T, noUnmarshal bool) (
	gb *GetBudgetResult, raw []byte, err error,
)

func (*Client) GetInfo

func (cl *Client) GetInfo(c context.T, noUnmarshal bool) (
	gi *GetInfoResult, raw []byte, err error,
)

func (*Client) GetWalletServiceInfo added in v0.4.15

func (cl *Client) GetWalletServiceInfo(c context.T, noUnmarshal bool) (
	wsi *WalletServiceInfo, raw []byte, err error,
)

func (*Client) ListTransactions

func (cl *Client) ListTransactions(
	c context.T, params *ListTransactionsParams, noUnmarshal bool,
) (lt *ListTransactionsResult, raw []byte, err error)

func (*Client) LookupInvoice

func (cl *Client) LookupInvoice(
	c context.T, params *LookupInvoiceParams, noUnmarshal bool,
) (li *LookupInvoiceResult, raw []byte, err error)

func (*Client) MakeHoldInvoice added in v0.5.0

func (cl *Client) MakeHoldInvoice(
	c context.T,
	mhi *MakeHoldInvoiceParams, noUnmarshal bool,
) (mi *MakeInvoiceResult, raw []byte, err error)

func (*Client) MakeInvoice

func (cl *Client) MakeInvoice(
	c context.T, params *MakeInvoiceParams, noUnmarshal bool,
) (mi *MakeInvoiceResult, raw []byte, err error)

func (*Client) PayInvoice

func (cl *Client) PayInvoice(
	c context.T, params *PayInvoiceParams, noUnmarshal bool,
) (pi *PayInvoiceResult, raw []byte, err error)

func (*Client) PayKeysend

func (cl *Client) PayKeysend(
	c context.T, params *PayKeysendParams, noUnmarshal bool,
) (pk *PayKeysendResult, raw []byte, err error)

func (*Client) RPC added in v0.4.15

func (cl *Client) RPC(
	c context.T, method Capability, params, result any, noUnmarshal bool,
	opts *rpcOptions,
) (raw []byte, err error)

func (*Client) SettleHoldInvoice added in v0.5.0

func (cl *Client) SettleHoldInvoice(
	c context.T, shi *SettleHoldInvoiceParams, noUnmarshal bool,
) (raw []byte, err error)

func (*Client) SignMessage

func (cl *Client) SignMessage(
	c context.T, sm *SignMessageParams, noUnmarshal bool,
) (res *SignMessageResult, raw []byte, err error)

func (*Client) Subscribe added in v0.6.1

func (cl *Client) Subscribe(c context.T) (evc event.C, err error)

type ConnectionParams added in v0.4.15

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

func ParseConnectionURI added in v0.4.15

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

func (*ConnectionParams) GetWalletPublicKey added in v0.5.0

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

GetWalletPublicKey returns the wallet public key from the ConnectionParams.

type CreateConnectionParams added in v0.5.0

type CreateConnectionParams struct {
	Pubkey            string   `json:"pubkey"`
	Name              string   `json:"name"`
	RequestMethods    []string `json:"request_methods"`
	NotificationTypes []string `json:"notification_types"`
	MaxAmount         *uint64  `json:"max_amount,omitempty"`
	BudgetRenewal     *string  `json:"budget_renewal,omitempty"`
	ExpiresAt         *int64   `json:"expires_at,omitempty"`
}

type EncryptionType

type EncryptionType []byte

EncryptionType represents the encryption type used for NIP-47 messages

type GetBalanceResult added in v0.4.15

type GetBalanceResult struct {
	Balance uint64 `json:"balance"`
}

type GetBudgetResult added in v0.5.0

type GetBudgetResult struct {
	UsedBudget    int    `json:"used_budget,omitempty"`
	TotalBudget   int    `json:"total_budget,omitempty"`
	RenewsAt      int    `json:"renews_at,omitempty"`
	RenewalPeriod string `json:"renewal_period,omitempty"`
}

type GetInfoResult added in v0.4.15

type GetInfoResult struct {
	Alias         string   `json:"alias"`
	Color         string   `json:"color"`
	Pubkey        string   `json:"pubkey"`
	Network       string   `json:"network"`
	BlockHeight   uint64   `json:"block_height"`
	BlockHash     string   `json:"block_hash"`
	Methods       []string `json:"methods"`
	Notifications []string `json:"notifications,omitempty"`
	Metadata      any      `json:"metadata,omitempty"`
	LUD16         string   `json:"lud16,omitempty"`
}

type ListTransactionsParams added in v0.4.15

type ListTransactionsParams struct {
	From           *int64  `json:"from,omitempty"`
	Until          *int64  `json:"until,omitempty"`
	Limit          *uint16 `json:"limit,omitempty"`
	Offset         *uint32 `json:"offset,omitempty"`
	Unpaid         *bool   `json:"unpaid,omitempty"`
	UnpaidOutgoing *bool   `json:"unpaid_outgoing,omitempty"`
	UnpaidIncoming *bool   `json:"unpaid_incoming,omitempty"`
	Type           *string `json:"type,omitempty"`
}

type ListTransactionsResult added in v0.4.15

type ListTransactionsResult struct {
	Transactions []Transaction `json:"transactions"`
	TotalCount   uint32        `json:"total_count"`
}

type LookupInvoiceParams added in v0.4.15

type LookupInvoiceParams struct {
	PaymentHash *string `json:"payment_hash,omitempty"`
	Invoice     *string `json:"invoice,omitempty"`
}

type LookupInvoiceResult added in v0.4.15

type LookupInvoiceResult = Transaction

type MakeHoldInvoiceParams added in v0.5.0

type MakeHoldInvoiceParams struct {
	Amount          uint64 `json:"amount"`
	PaymentHash     string `json:"payment_hash"`
	Description     string `json:"description,omitempty"`
	DescriptionHash string `json:"description_hash,omitempty"`
	Expiry          *int64 `json:"expiry,omitempty"`
	Metadata        any    `json:"metadata,omitempty"`
}

type MakeInvoiceParams added in v0.4.15

type MakeInvoiceParams struct {
	Amount          uint64 `json:"amount"`
	Description     string `json:"description,omitempty"`
	DescriptionHash string `json:"description_hash,omitempty"`
	Expiry          *int64 `json:"expiry,omitempty"`
	Metadata        any    `json:"metadata,omitempty"`
}

type MakeInvoiceResult added in v0.4.15

type MakeInvoiceResult = Transaction

type MethodHandler added in v0.6.1

type MethodHandler func(
	c context.T, params json.RawMessage,
) (result interface{}, err error)

MethodHandler is a function type for handling wallet service method calls.

type NotificationType

type NotificationType []byte

type PayInvoiceMetadata added in v0.5.0

type PayInvoiceMetadata struct {
	Comment   *string              `json:"comment"`
	PayerData *PayInvoicePayerData `json:"payer_data"`
	Other     any
}

type PayInvoiceParams added in v0.4.15

type PayInvoiceParams struct {
	Invoice  string              `json:"invoice"`
	Amount   *uint64             `json:"amount,omitempty"`
	Metadata *PayInvoiceMetadata `json:"metadata,omitempty"`
}

type PayInvoicePayerData added in v0.5.0

type PayInvoicePayerData struct {
	Email  string `json:"email"`
	Name   string `json:"name"`
	Pubkey string `json:"pubkey"`
}

type PayInvoiceResult added in v0.4.15

type PayInvoiceResult struct {
	Preimage string `json:"preimage"`
	FeesPaid uint64 `json:"fees_paid"`
}

type PayKeysendParams added in v0.5.0

type PayKeysendParams struct {
	Amount     uint64                `json:"amount"`
	Pubkey     string                `json:"pubkey"`
	Preimage   *string               `json:"preimage,omitempty"`
	TLVRecords []PayKeysendTLVRecord `json:"tlv_records,omitempty"`
}

type PayKeysendResult added in v0.5.0

type PayKeysendResult = PayInvoiceResult

type PayKeysendTLVRecord added in v0.5.0

type PayKeysendTLVRecord struct {
	Type  uint32 `json:"type"`
	Value string `json:"value"`
}

type Request added in v0.4.15

type Request struct {
	Method string `json:"method"`
	Params any    `json:"params"`
}

type Response added in v0.4.15

type Response struct {
	ResultType string         `json:"result_type"`
	Error      *ResponseError `json:"error"`
	Result     any            `json:"result"`
}

type ResponseError added in v0.4.15

type ResponseError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

func (*ResponseError) Error added in v0.4.15

func (err *ResponseError) Error() string

type SettleHoldInvoiceParams added in v0.5.0

type SettleHoldInvoiceParams struct {
	Preimage string `json:"preimage"`
}

type SignMessageParams added in v0.5.0

type SignMessageParams struct {
	Message string `json:"message"`
}

type SignMessageResult added in v0.5.0

type SignMessageResult struct {
	Message   string `json:"message"`
	Signature string `json:"signature"`
}

type Transaction

type Transaction struct {
	Type            string  `json:"type"`
	State           string  `json:"state"`
	Invoice         string  `json:"invoice"`
	Description     string  `json:"description"`
	DescriptionHash string  `json:"description_hash"`
	Preimage        string  `json:"preimage"`
	PaymentHash     string  `json:"payment_hash"`
	Amount          uint64  `json:"amount"`
	FeesPaid        uint64  `json:"fees_paid"`
	CreatedAt       int64   `json:"created_at"`
	ExpiresAt       int64   `json:"expires_at"`
	SettledDeadline *uint64 `json:"settled_deadline,omitempty"`
	Metadata        any     `json:"metadata,omitempty"`
}

type WalletService added in v0.6.1

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

WalletService represents a wallet service that clients can connect to.

func NewWalletService added in v0.6.1

func NewWalletService(
	listener *ws.Listener, walletKey signer.I,
) (ws *WalletService, err error)

NewWalletService creates a new WalletService with the given listener and wallet key.

func (*WalletService) HandleRequest added in v0.6.1

func (ws *WalletService) HandleRequest(c context.T, ev *event.E) (err error)

HandleRequest processes an incoming wallet request event.

func (*WalletService) RegisterHandler added in v0.6.1

func (ws *WalletService) RegisterHandler(
	method string, handler MethodHandler,
)

RegisterHandler registers a handler for a specific method.

func (*WalletService) SendNotification added in v0.6.1

func (ws *WalletService) SendNotification(
	c context.T, clientPubKey []byte, notificationType string,
	content interface{},
) (err error)

SendNotification sends a notification to a client.

type WalletServiceInfo added in v0.4.15

type WalletServiceInfo struct {
	EncryptionTypes   []EncryptionType
	Capabilities      []Capability
	NotificationTypes []NotificationType
}

Jump to

Keyboard shortcuts

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