pub struct SpilmanClientBridge<H: SpilmanClientHost, N: SpilmanClientNetworking> { /* private fields */ }Expand description
Client-side bridge for managing Spilman payment channels.
This is the client-side counterpart of SpilmanBridge. It orchestrates
channel creation from tokens, payment signing, and HTTP header construction.
The bridge itself is stateless — all channel state is stored via the host. The bridge never holds or sees Alice’s secret key; all operations requiring the key are delegated to the host via callbacks.
Implementations§
Source§impl<H: SpilmanClientHost, N: SpilmanClientNetworking> SpilmanClientBridge<H, N>
impl<H: SpilmanClientHost, N: SpilmanClientNetworking> SpilmanClientBridge<H, N>
Sourcepub fn new(host: H, networking: N) -> Self
pub fn new(host: H, networking: N) -> Self
Create a new client bridge.
The bridge is stateless and keyless — it delegates all key operations
to the host. The caller passes sender_pubkey_hex per channel when
opening channels.
Sourcepub fn create_payment(
&self,
channel_id: &str,
balance: u64,
) -> Result<Payment, String>
pub fn create_payment( &self, channel_id: &str, balance: u64, ) -> Result<Payment, String>
Create a payment for a channel (without funding data).
Returns a Payment struct ready to send to the server.
Use this for subsequent payments after the channel is registered.
The balance is the cumulative amount the receiver can claim.
§Errors
- Returns an error if the channel doesn’t exist or is closed
- Returns an error if
balanceexceeds the channel capacity
Sourcepub fn create_payment_with_funding(
&self,
channel_id: &str,
balance: u64,
) -> Result<Payment, String>
pub fn create_payment_with_funding( &self, channel_id: &str, balance: u64, ) -> Result<Payment, String>
Create a payment with funding data (for first payment).
Returns a Payment struct with params and funding_proofs included.
Use this for the first payment when registering a channel with the server.
The same validation rules apply as create_payment().
Sourcepub fn build_payment_header(
&self,
channel_id: &str,
balance: u64,
include_funding: bool,
) -> Result<String, String>
pub fn build_payment_header( &self, channel_id: &str, balance: u64, include_funding: bool, ) -> Result<String, String>
Build a complete X-Cashu-Channel payment header value.
Returns a base64-encoded JSON string ready to use as the header value.
If include_funding is true, the header includes params and funding_proofs
(needed for the first request, or when the server doesn’t know this channel yet).
Sourcepub fn get_channel_info(&self, channel_id: &str) -> Option<ClientChannelInfo>
pub fn get_channel_info(&self, channel_id: &str) -> Option<ClientChannelInfo>
Get information about a stored channel.
Sourcepub fn list_channels(&self) -> Vec<String>
pub fn list_channels(&self) -> Vec<String>
List all stored channel IDs.
Sourcepub fn close_channel(&self, channel_id: &str)
pub fn close_channel(&self, channel_id: &str)
Close a channel locally.
Marks the channel as closed so no more payments can be made. Does not communicate with the server.
Sourcepub fn delete_channel(&self, channel_id: &str)
pub fn delete_channel(&self, channel_id: &str)
Delete a channel from storage.
Removes all data associated with the channel.
Sourcepub fn create_cooperative_close_request(
&self,
channel_id: &str,
final_balance: u64,
) -> Result<Payment, String>
pub fn create_cooperative_close_request( &self, channel_id: &str, final_balance: u64, ) -> Result<Payment, String>
Create a cooperative close request for a channel.
Creates a payment at the final balance that can be sent to the server’s close endpoint.
Sourcepub fn process_cooperative_close_response(
&self,
response_json: &str,
) -> Result<(), String>
pub fn process_cooperative_close_response( &self, response_json: &str, ) -> Result<(), String>
Process a cooperative close response from the server.
Marks the channel as closed locally.
Sourcepub fn create_unsigned_balance_update(
&self,
channel_id: &str,
balance: u64,
funding: &ClientChannelFunding,
) -> Result<UnsignedBalanceUpdate, String>
pub fn create_unsigned_balance_update( &self, channel_id: &str, balance: u64, funding: &ClientChannelFunding, ) -> Result<UnsignedBalanceUpdate, String>
Create an unsigned balance update for a channel.
This computes the message hash and tweak scalar needed for signing.
The caller can inspect the UnsignedBalanceUpdate, then call
sign_balance_update() to produce a BalanceUpdateMessage.
For most use cases, prefer create_payment() which handles signing
automatically via the host.
Sourcepub fn sign_balance_update(
&self,
unsigned: UnsignedBalanceUpdate,
sender_pubkey_hex: &str,
) -> Result<BalanceUpdateMessage, String>
pub fn sign_balance_update( &self, unsigned: UnsignedBalanceUpdate, sender_pubkey_hex: &str, ) -> Result<BalanceUpdateMessage, String>
Sign an unsigned balance update using the host.
Delegates to host.sign_with_tweaked_key() to produce the signature,
then assembles the final BalanceUpdateMessage.