Skip to main content

SpilmanClientBridge

Struct SpilmanClientBridge 

Source
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>

Source

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.

Source

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 balance exceeds the channel capacity
Source

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().

Source

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).

Source

pub fn get_channel_info(&self, channel_id: &str) -> Option<ClientChannelInfo>

Get information about a stored channel.

Source

pub fn list_channels(&self) -> Vec<String>

List all stored channel IDs.

Source

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.

Source

pub fn delete_channel(&self, channel_id: &str)

Delete a channel from storage.

Removes all data associated with the channel.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<H: Debug + SpilmanClientHost, N: Debug + SpilmanClientNetworking> Debug for SpilmanClientBridge<H, N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<H, N> Freeze for SpilmanClientBridge<H, N>
where H: Freeze, N: Freeze,

§

impl<H, N> RefUnwindSafe for SpilmanClientBridge<H, N>

§

impl<H, N> Send for SpilmanClientBridge<H, N>
where H: Send, N: Send,

§

impl<H, N> Sync for SpilmanClientBridge<H, N>
where H: Sync, N: Sync,

§

impl<H, N> Unpin for SpilmanClientBridge<H, N>
where H: Unpin, N: Unpin,

§

impl<H, N> UnsafeUnpin for SpilmanClientBridge<H, N>
where H: UnsafeUnpin, N: UnsafeUnpin,

§

impl<H, N> UnwindSafe for SpilmanClientBridge<H, N>
where H: UnwindSafe, N: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more