nwc

package
v0.4.13 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: Unlicense Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthorizationUrlOptions

type AuthorizationUrlOptions struct {
	Name              string              `json:"name,omitempty"`
	Icon              string              `json:"icon,omitempty"`
	RequestMethods    []Method            `json:"requestMethods,omitempty"`
	NotificationTypes []NotificationType  `json:"notificationTypes,omitempty"`
	ReturnTo          string              `json:"returnTo,omitempty"`
	ExpiresAt         *time.Time          `json:"expiresAt,omitempty"`
	MaxAmount         *int64              `json:"maxAmount,omitempty"`
	BudgetRenewal     BudgetRenewalPeriod `json:"budgetRenewal,omitempty"`
	Isolated          bool                `json:"isolated,omitempty"`
	Metadata          interface{}         `json:"metadata,omitempty"`
}

AuthorizationUrlOptions represents options for creating an NWC authorization URL

type BudgetRenewalPeriod

type BudgetRenewalPeriod string

BudgetRenewalPeriod represents a budget renewal period

const (
	Daily   BudgetRenewalPeriod = "daily"
	Weekly  BudgetRenewalPeriod = "weekly"
	Monthly BudgetRenewalPeriod = "monthly"
	Yearly  BudgetRenewalPeriod = "yearly"
	Never   BudgetRenewalPeriod = "never"
)

type CancelHoldInvoiceRequest

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

CancelHoldInvoiceRequest represents a request to cancel a hold invoice

type CancelHoldInvoiceResponse

type CancelHoldInvoiceResponse struct{}

CancelHoldInvoiceResponse represents a response to a cancel_hold_invoice request

type Capability

type Capability string

Capability represents a NIP-47 capability

const (
	Notifications Capability = "notifications"
)

type Client

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

Client represents a NWC client

func NewNWCClient

func NewNWCClient(options *Options) (cl *Client, err error)

NewNWCClient creates a new NWC client

func (*Client) Close

func (c *Client) Close()

Close closes the relay connection

func (*Client) Connected

func (c *Client) Connected() bool

Connected returns whether the client is connected to the relay

func (*Client) GetBalance

func (c *Client) GetBalance() (response *GetBalanceResponse, err error)

GetBalance gets wallet balance

func (*Client) GetBudget

func (c *Client) GetBudget() (response *GetBudgetResponse, err error)

GetBudget gets wallet budget

func (*Client) GetInfo

func (c *Client) GetInfo() (response *GetInfoResponse, err error)

GetInfo gets wallet info

func (*Client) GetNostrWalletConnectURL

func (c *Client) GetNostrWalletConnectURL(includeSecret bool) string

GetNostrWalletConnectURL returns the nostr wallet connect URL

func (*Client) GetPublicKey

func (c *Client) GetPublicKey() (pubkey []byte, err error)

GetPublicKey returns the client's public key

func (*Client) ListTransactions

func (c *Client) ListTransactions(request *ListTransactionsRequest) (
	response *ListTransactionsResponse, err error,
)

ListTransactions lists transactions

func (*Client) LookupInvoice

func (c *Client) LookupInvoice(request *LookupInvoiceRequest) (
	response *Transaction, err error,
)

LookupInvoice looks up an invoice

func (*Client) MakeInvoice

func (c *Client) MakeInvoice(request *MakeInvoiceRequest) (
	response *Transaction, err error,
)

MakeInvoice creates an invoice

func (*Client) NostrWalletConnectURL

func (c *Client) NostrWalletConnectURL() string

NostrWalletConnectURL returns the nostr wallet connect URL

func (*Client) PayInvoice

func (c *Client) PayInvoice(request *PayInvoiceRequest) (
	response *PayResponse, err error,
)

PayInvoice pays an invoice

func (*Client) PayKeysend

func (c *Client) PayKeysend(request *PayKeysendRequest) (
	response *PayResponse, err error,
)

PayKeysend sends a keysend payment

func (*Client) SignMessage

func (c *Client) SignMessage(request *SignMessageRequest) (
	response *SignMessageResponse, err error,
)

SignMessage signs a message

func (*Client) SubscribeNotifications

func (c *Client) SubscribeNotifications(
	handler NotificationHandler,
	notificationTypes []NotificationType,
) (stop func(), err error)

SubscribeNotifications subscribes to notifications

type CreateConnectionRequest

type CreateConnectionRequest struct {
	Pubkey            string               `json:"pubkey"`
	Name              string               `json:"name"`
	RequestMethods    []Method             `json:"request_methods"`
	NotificationTypes []NotificationType   `json:"notification_types,omitempty"`
	MaxAmount         *int64               `json:"max_amount,omitempty"`
	BudgetRenewal     *BudgetRenewalPeriod `json:"budget_renewal,omitempty"`
	ExpiresAt         *int64               `json:"expires_at,omitempty"`
	Isolated          *bool                `json:"isolated,omitempty"`
	Metadata          any                  `json:"metadata,omitempty"`
}

CreateConnectionRequest represents a request to create a connection

type CreateConnectionResponse

type CreateConnectionResponse struct {
	WalletPubkey string `json:"wallet_pubkey"`
}

CreateConnectionResponse represents a response to a create_connection request

type EncryptionType

type EncryptionType string

EncryptionType represents the encryption type used for NIP-47 messages

const (
	Nip04   EncryptionType = "nip04"
	Nip44V2 EncryptionType = "nip44_v2"
)

type Err

type Err struct {
	Message string
	Code    string
}

Err is the base error type for NIP-47 errors

func NewError

func NewError(message, code string) *Err

NewError creates a new Error

func (*Err) Error

func (e *Err) Error() string

type GetBalanceResponse

type GetBalanceResponse struct {
	Balance int64 `json:"balance"` // msats
}

GetBalanceResponse represents a response to a get_balance request

type GetBudgetResponse

type GetBudgetResponse struct {
	UsedBudget    int64               `json:"used_budget,omitempty"`
	TotalBudget   int64               `json:"total_budget,omitempty"`
	RenewsAt      *int64              `json:"renews_at,omitempty"`
	RenewalPeriod BudgetRenewalPeriod `json:"renewal_period,omitempty"`
}

GetBudgetResponse represents a response to a get_budget request

type GetInfoResponse

type GetInfoResponse struct {
	Alias         string             `json:"alias"`
	Color         string             `json:"color"`
	Pubkey        string             `json:"pubkey"`
	Network       string             `json:"network"`
	BlockHeight   int64              `json:"block_height"`
	BlockHash     string             `json:"block_hash"`
	Methods       []Method           `json:"methods"`
	Notifications []NotificationType `json:"notifications,omitempty"`
	Metadata      interface{}        `json:"metadata,omitempty"`
	Lud16         string             `json:"lud16,omitempty"`
}

GetInfoResponse represents a response to a get_info request

type ListTransactionsRequest

type ListTransactionsRequest struct {
	From           *int64  `json:"from,omitempty"`
	Until          *int64  `json:"until,omitempty"`
	Limit          *int64  `json:"limit,omitempty"`
	Offset         *int64  `json:"offset,omitempty"`
	Unpaid         *bool   `json:"unpaid,omitempty"`
	UnpaidOutgoing *bool   `json:"unpaid_outgoing,omitempty"` // NOTE: non-NIP-47 spec compliant
	UnpaidIncoming *bool   `json:"unpaid_incoming,omitempty"` // NOTE: non-NIP-47 spec compliant
	Type           *string `json:"type,omitempty"`            // "incoming" or "outgoing"
}

ListTransactionsRequest represents a request to list transactions

type ListTransactionsResponse

type ListTransactionsResponse struct {
	Transactions []Transaction `json:"transactions"`
	TotalCount   int64         `json:"total_count"` // NOTE: non-NIP-47 spec compliant
}

ListTransactionsResponse represents a response to a list_transactions request

type LookupInvoiceRequest

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

LookupInvoiceRequest represents a request to lookup an invoice

type MakeHoldInvoiceRequest

type MakeHoldInvoiceRequest struct {
	MakeInvoiceRequest
	PaymentHash string `json:"payment_hash"`
}

MakeHoldInvoiceRequest represents a request to make a hold invoice

type MakeInvoiceRequest

type MakeInvoiceRequest struct {
	Amount          int64                `json:"amount"` // msats
	Description     string               `json:"description,omitempty"`
	DescriptionHash string               `json:"description_hash,omitempty"`
	Expiry          *int64               `json:"expiry,omitempty"` // in seconds
	Metadata        *TransactionMetadata `json:"metadata,omitempty"`
}

MakeInvoiceRequest represents a request to make an invoice

type Method

type Method string

Method represents a NIP-47 method

const (
	GetInfo           Method = "get_info"
	GetBalance        Method = "get_balance"
	GetBudget         Method = "get_budget"
	MakeInvoice       Method = "make_invoice"
	PayInvoice        Method = "pay_invoice"
	PayKeysend        Method = "pay_keysend"
	LookupInvoice     Method = "lookup_invoice"
	ListTransactions  Method = "list_transactions"
	SignMessage       Method = "sign_message"
	CreateConnection  Method = "create_connection"
	MakeHoldInvoice   Method = "make_hold_invoice"
	SettleHoldInvoice Method = "settle_hold_invoice"
	CancelHoldInvoice Method = "cancel_hold_invoice"
)

SingleMethod represents a single NIP-47 method

const (
	MultiPayInvoice Method = "multi_pay_invoice"
	MultiPayKeysend Method = "multi_pay_keysend"
)

MultiMethod represents a multi NIP-47 method

type MultiPayInvoiceRequest

type MultiPayInvoiceRequest struct {
	Invoices []PayInvoiceRequestWithID `json:"invoices"`
}

MultiPayInvoiceRequest represents a request to pay multiple invoices

type MultiPayInvoiceResponse

type MultiPayInvoiceResponse struct {
	Invoices []MultiPayInvoiceResponseItem `json:"invoices"`
	Errors   []interface{}                 `json:"errors"` // TODO: add error handling
}

MultiPayInvoiceResponse represents a response to a multi_pay_invoice request

type MultiPayInvoiceResponseItem

type MultiPayInvoiceResponseItem struct {
	Invoice PayInvoiceRequest `json:"invoice"`
	PayResponse
	WithDTag
}

MultiPayInvoiceResponseItem represents an item in a multi_pay_invoice response

type MultiPayKeysendRequest

type MultiPayKeysendRequest struct {
	Keysends []PayKeysendRequestWithID `json:"keysends"`
}

MultiPayKeysendRequest represents a request to pay multiple keysends

type MultiPayKeysendResponse

type MultiPayKeysendResponse struct {
	Keysends []MultiPayKeysendResponseItem `json:"keysends"`
	Errors   []interface{}                 `json:"errors"` // TODO: add error handling
}

MultiPayKeysendResponse represents a response to a multi_pay_keysend request

type MultiPayKeysendResponseItem

type MultiPayKeysendResponseItem struct {
	Keysend PayKeysendRequest `json:"keysend"`
	PayResponse
	WithDTag
}

MultiPayKeysendResponseItem represents an item in a multi_pay_keysend response

type NetworkError

type NetworkError struct{ *Err }

NetworkError represents a network error in NIP-47 operations

func NewNetworkError

func NewNetworkError(message, code string) *NetworkError

NewNetworkError creates a new NetworkError

type NostrData

type NostrData struct {
	Pubkey string     `json:"pubkey"`
	Tags   [][]string `json:"tags"`
}

NostrData represents Nostr data for a transaction

type Notification

type Notification struct {
	NotificationType NotificationType `json:"notification_type"`
	Notification     Transaction      `json:"notification"`
}

Notification represents a notification

type NotificationHandler

type NotificationHandler func(*Notification)

NotificationHandler is a function that handles notifications

type NotificationType

type NotificationType string

NotificationType represents a notification type

const (
	PaymentReceived     NotificationType = "payment_received"
	PaymentSent         NotificationType = "payment_sent"
	HoldInvoiceAccepted NotificationType = "hold_invoice_accepted"
)

type Options

type Options struct {
	RelayURL     string
	Secret       signer.I
	WalletPubkey []byte
	Lud16        string
}

Options represents options for a NWC client

func ParseWalletConnectURL

func ParseWalletConnectURL(walletConnectURL string) (opts *Options, err error)

ParseWalletConnectURL parses a wallet connect URL

type PayInvoiceRequest

type PayInvoiceRequest struct {
	Invoice  string               `json:"invoice"`
	Metadata *TransactionMetadata `json:"metadata,omitempty"`
	Amount   *int64               `json:"amount,omitempty"` // msats
}

PayInvoiceRequest represents a request to pay an invoice

type PayInvoiceRequestWithID

type PayInvoiceRequestWithID struct {
	PayInvoiceRequest
	WithOptionalId
}

PayInvoiceRequestWithID combines PayInvoiceRequest with WithOptionalId

type PayKeysendRequest

type PayKeysendRequest struct {
	Amount     int64       `json:"amount"` // msats
	Pubkey     string      `json:"pubkey"`
	Preimage   string      `json:"preimage,omitempty"`
	TlvRecords []TlvRecord `json:"tlv_records,omitempty"`
}

PayKeysendRequest represents a request to pay a keysend

type PayKeysendRequestWithID

type PayKeysendRequestWithID struct {
	PayKeysendRequest
	WithOptionalId
}

PayKeysendRequestWithID combines PayKeysendRequest with WithOptionalId

type PayResponse

type PayResponse struct {
	Preimage string `json:"preimage"`
	FeesPaid int64  `json:"fees_paid"`
}

PayResponse represents a response to a pay request

type PayerData

type PayerData struct {
	Email  string `json:"email,omitempty"`
	Name   string `json:"name,omitempty"`
	Pubkey string `json:"pubkey,omitempty"`
}

PayerData represents payer data for a transaction

type PublishError

type PublishError struct{ *Err }

PublishError represents a publish error in NIP-47 operations

func NewPublishError

func NewPublishError(message, code string) *PublishError

NewPublishError creates a new PublishError

type PublishTimeoutError

type PublishTimeoutError struct{ *TimeoutError }

PublishTimeoutError represents a publish timeout error in NIP-47 operations

func NewPublishTimeoutError

func NewPublishTimeoutError(message, code string) *PublishTimeoutError

NewPublishTimeoutError creates a new PublishTimeoutError

type RecipientData

type RecipientData struct {
	Identifier string `json:"identifier,omitempty"`
}

RecipientData represents recipient data for a transaction

type ReplyTimeoutError

type ReplyTimeoutError struct{ *TimeoutError }

ReplyTimeoutError represents a reply timeout error in NIP-47 operations

func NewReplyTimeoutError

func NewReplyTimeoutError(message, code string) *ReplyTimeoutError

NewReplyTimeoutError creates a new ReplyTimeoutError

type ResponseDecodingError

type ResponseDecodingError struct{ *Err }

ResponseDecodingError represents a response decoding error in NIP-47 operations

func NewResponseDecodingError

func NewResponseDecodingError(message, code string) *ResponseDecodingError

NewResponseDecodingError creates a new ResponseDecodingError

type ResponseValidationError

type ResponseValidationError struct{ *Err }

ResponseValidationError represents a response validation error in NIP-47 operations

func NewResponseValidationError

func NewResponseValidationError(message, code string) *ResponseValidationError

NewResponseValidationError creates a new ResponseValidationError

type SettleHoldInvoiceRequest

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

SettleHoldInvoiceRequest represents a request to settle a hold invoice

type SettleHoldInvoiceResponse

type SettleHoldInvoiceResponse struct{}

SettleHoldInvoiceResponse represents a response to a settle_hold_invoice request

type SignMessageRequest

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

SignMessageRequest represents a request to sign a message

type SignMessageResponse

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

SignMessageResponse represents a response to a sign_message request

type TimeoutError

type TimeoutError struct{ *Err }

TimeoutError represents a timeout error in NIP-47 operations

func NewTimeoutError

func NewTimeoutError(message, code string) *TimeoutError

NewTimeoutError creates a new TimeoutError

type TimeoutValues

type TimeoutValues struct {
	ReplyTimeout   *int64 `json:"replyTimeout,omitempty"`
	PublishTimeout *int64 `json:"publishTimeout,omitempty"`
}

TimeoutValues represents timeout values for NIP-47 requests

type TlvRecord

type TlvRecord struct {
	Type  int64  `json:"type"`
	Value string `json:"value"`
}

TlvRecord represents a TLV record

type Transaction

type Transaction struct {
	Type            TransactionType      `json:"type"`
	State           TransactionState     `json:"state"` // NOTE: non-NIP-47 spec compliant
	Invoice         string               `json:"invoice"`
	Description     string               `json:"description"`
	DescriptionHash string               `json:"description_hash"`
	Preimage        string               `json:"preimage"`
	PaymentHash     string               `json:"payment_hash"`
	Amount          int64                `json:"amount"`
	FeesPaid        int64                `json:"fees_paid"`
	SettledAt       int64                `json:"settled_at"`
	CreatedAt       int64                `json:"created_at"`
	ExpiresAt       int64                `json:"expires_at"`
	SettleDeadline  *int64               `json:"settle_deadline,omitempty"` // NOTE: non-NIP-47 spec compliant
	Metadata        *TransactionMetadata `json:"metadata,omitempty"`
}

Transaction represents a transaction

type TransactionMetadata

type TransactionMetadata struct {
	Comment       string                 `json:"comment,omitempty"`        // LUD-12
	PayerData     *PayerData             `json:"payer_data,omitempty"`     // LUD-18
	RecipientData *RecipientData         `json:"recipient_data,omitempty"` // LUD-18
	Nostr         *NostrData             `json:"nostr,omitempty"`          // NIP-57
	ExtraData     map[string]interface{} `json:"-"`                        // For additional fields
}

TransactionMetadata represents metadata for a transaction

type TransactionState

type TransactionState string

TransactionState represents the state of a transaction

const (
	Settled TransactionState = "settled"
	Pending TransactionState = "pending"
	Failed  TransactionState = "failed"
)

type TransactionType

type TransactionType string

TransactionType represents the type of a transaction

const (
	Incoming TransactionType = "incoming"
	Outgoing TransactionType = "outgoing"
)

type UnexpectedResponseError

type UnexpectedResponseError struct{ *Err }

UnexpectedResponseError represents an unexpected response error in NIP-47 operations

func NewUnexpectedResponseError

func NewUnexpectedResponseError(message, code string) *UnexpectedResponseError

NewUnexpectedResponseError creates a new UnexpectedResponseError

type UnsupportedEncryptionError

type UnsupportedEncryptionError struct {
	*Err
}

UnsupportedEncryptionError represents an unsupported encryption error in NIP-47 operations

func NewUnsupportedEncryptionError

func NewUnsupportedEncryptionError(message, code string) *UnsupportedEncryptionError

NewUnsupportedEncryptionError creates a new UnsupportedEncryptionError

type WalletError

type WalletError struct {
	*Err
}

WalletError represents a wallet error in NIP-47 operations

func NewWalletError

func NewWalletError(message, code string) *WalletError

NewWalletError creates a new WalletError

type WithDTag

type WithDTag struct {
	DTag string `json:"dTag"`
}

WithDTag represents a type with a dTag field

type WithOptionalId

type WithOptionalId struct {
	ID string `json:"id,omitempty"`
}

WithOptionalId represents a type with an optional id field

Jump to

Keyboard shortcuts

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