Overview
@nuwa-ai/payment-kit implements Nuwa’s unidirectional payment channels (NIP-4) for HTTP and MCP. It manages channel lifecycle, SubRAV receipts, streaming, and settlement.
Install
HTTP Client
createHttpClient
Factory that builds a PaymentChannelHttpClient from an IdentityEnv. Inputs Creation optionsobject
required
PaymentChannelHttpClient
Configured HTTP payer client
PaymentChannelHttpClient.requestWithPayment
Create a payable request and return both response and payment promises. Inputs"GET"|"POST"|"PUT"|"DELETE"|"PATCH"
required
HTTP method
string
required
Relative URL or path
RequestInit?
Headers, body, and signal
string
Correlation id
Promise
Raw fetch response promise
Promise
Resolved payment info (PaymentInfo or undefined)
Promise
Resolves to object with
data and paymentfunction
Cancel the request
PaymentChannelHttpClient.request
Convenience wrapper returning only the HTTP response. Inputs"GET"|"POST"|"PUT"|"DELETE"|"PATCH"
required
HTTP method
string
required
Relative URL or path
RequestInit?
Request options
Promise
Raw fetch response promise
PaymentChannelHttpClient.requestAndWaitForPayment
Wait for both HTTP response and payment resolution. Inputs"GET"|"POST"|"PUT"|"DELETE"|"PATCH"
required
HTTP method
string
required
Relative URL or path
RequestInit?
Request options
Response
Raw fetch response
PaymentInfo | undefined
Payment result (if billed)
PaymentChannelHttpClient.get/post/put/patch/delete
JSON helpers that parse the response and return{ data, payment }.
Inputs
string
required
Relative URL or path
any?
JSON body for POST/PUT/PATCH
RequestInit?
Request options
any
Parsed JSON payload
PaymentInfo | undefined
Payment result (if billed)
PaymentChannelHttpClient.getPendingSubRAV
Return the latest unsigned proposal (if any). Inputsvoid
No input parameters
SubRAV | null
Current pending SubRAV
PaymentChannelHttpClient.getPayerClient
Access the low-level payer client. Inputsvoid
No input parameters
PaymentChannelPayerClient
Low-level client
PaymentChannelHttpClient.healthCheck
Check service health (free). Inputsvoid
No input parameters
HealthResponse
Server health payload
PaymentChannelHttpClient.recoverFromService
Recover latest SubRAV from service after failures. Inputsvoid
No input parameters
RecoveryResponse
Recovery payload
PaymentChannelHttpClient.logoutCleanup
Abort pending requests, reset state, and optionally clear persisted mapping. Inputsboolean?
default:"true"
Delete persisted mapping store
string?
Optional note for logs
void
No return value
MCP Client
PaymentChannelMcpClient (constructor)
Create an MCP client with payment channels.object
required
PaymentChannelMcpClient
PaymentChannelMcpClient.callTool
Call an MCP tool; payment handled internally.string
required
any?
Tool params
object
Object containing
content: any[]PaymentChannelMcpClient.callToolWithPayment
Call a tool and return both business content and payment info.string
required
any?
Tool params
string?
Correlation id
object
Object with
content and optional paymentPaymentChannelMcpClient.listTools
List server tools with internal reserved params removed.object?
Optional flags (e.g., includeBuiltinTools)
record
Map of tool name to definition
PaymentChannelMcpClient.tools
Return AI SDK compatible ToolSet.ToolSet
PaymentChannelMcpClient.listPrompts / loadPrompt
Prompt discovery helpers.string?
For loadPrompt
any?
Prompt args
any | string
PaymentChannelMcpClient.listResources / listResourceTemplates / readResource
Resource discovery helpers.string | object?
For readResource (string or
uri object)any[] | any
PaymentChannelMcpClient.getPendingSubRAV / commitSubRAV
Inspect or commit pending SubRAV.SignedSubRAV
For commitSubRAV
SubRAV | object | null
Signed subRAV or success marker or null
PaymentChannelMcpClient.healthCheck / recoverFromService
Free endpoints for health and recovery.HealthResponse | RecoveryResponse
PaymentChannelMcpClient.close / clearPersistedState / getPayerClient / getTransactionStore
Lifecycle and accessors.void | PaymentChannelPayerClient | TransactionStore

