Skip to main content

ChannelParameters

Struct ChannelParameters 

Source
pub struct ChannelParameters {
    pub sender_pubkey: PublicKey,
    pub receiver_pubkey: PublicKey,
    pub mint: String,
    pub unit: CurrencyUnit,
    pub capacity: u64,
    pub funding_token_amount: u64,
    pub expiry_timestamp: u64,
    pub setup_timestamp: u64,
    pub keyset_info: KeysetInfo,
    pub maximum_amount_for_one_output: u64,
    pub channel_secret: [u8; 32],
}
Expand description

Parameters for a Spilman payment channel

Fields§

§sender_pubkey: PublicKey

Alice’s public key (sender)

§receiver_pubkey: PublicKey

Charlie’s public key (receiver)

§mint: String

Mint URL (or “local” for in-process mint)

§unit: CurrencyUnit

Currency unit for the channel

§capacity: u64

Channel capacity: maximum final value (after both fee stages) that Charlie can receive

§funding_token_amount: u64

Total nominal value of the funding token (must satisfy: capacity <= forward(forward(funding_token_amount)))

§expiry_timestamp: u64

Expiry timestamp after which Alice can reclaim funds (unix timestamp)

§setup_timestamp: u64

Setup timestamp (unix timestamp when channel was created)

§keyset_info: KeysetInfo

Keyset information (ID, keys, amounts, fees)

§maximum_amount_for_one_output: u64

Maximum amount for one output (amounts larger than this are filtered out)

§channel_secret: [u8; 32]

Channel secret: a domain-separated hash of the ECDH shared secret between Alice and Charlie

Implementations§

Source§

impl ChannelParameters

Source

pub fn get_sender_blinded_pubkey_for_stage1(&self) -> Result<PublicKey>

Get the blinded sender (Alice) pubkey for stage 1 P2BK

Computes the blinded pubkey that corresponds to Alice’s blinded secret key. This handles BIP-340 parity: if Alice’s pubkey has odd Y, we negate it first.

The formula matches derive_blinded_secret_key:

  • If even Y: P’ = P + r*G (matches k = p + r)
  • If odd Y: P’ = -P + r*G (matches k = -p + r)
Source

pub fn get_receiver_blinded_pubkey_for_stage1(&self) -> Result<PublicKey>

Get the blinded receiver (Charlie) pubkey for stage 1 P2BK

Computes the blinded pubkey that corresponds to Charlie’s blinded secret key. This handles BIP-340 parity: if Charlie’s pubkey has odd Y, we negate it first.

The formula matches derive_blinded_secret_key:

  • If even Y: P’ = P + r*G (matches k = p + r)
  • If odd Y: P’ = -P + r*G (matches k = -p + r)
Source

pub fn get_sender_blinded_secret_key_for_stage1( &self, alice_secret: &SecretKey, ) -> Result<SecretKey>

Derive the blinded sender secret key for stage 1 signing

For P2BK, Alice must sign with a blinded private key k such that k*G = P’. This handles BIP-340 parity: if Alice’s pubkey has odd Y, we negate her private key before adding the blinding scalar.

Source

pub fn derive_sender_blinding_scalar_for_stage1(&self) -> Result<Scalar>

Get the sender’s P2BK blinding scalar for stage 1 signing.

This is the tweak scalar that must be added to Alice’s secret key (with BIP-340 parity handling) to produce the blinded signing key. Used by the external signer flow in SpilmanClientBridge.

Source

pub fn derive_receiver_blinding_scalar_for_stage1(&self) -> Result<Scalar>

Get the receiver’s P2BK blinding scalar for stage 1 signing.

This is the tweak scalar that must be added to Charlie’s secret key (with BIP-340 parity handling) to produce the blinded signing key. Used by the external signer flow in SpilmanBridge.

Source

pub fn get_sender_blinded_pubkey_for_stage1_refund(&self) -> Result<PublicKey>

Get the blinded sender (Alice) pubkey for stage 1 expiry refund

Uses a DIFFERENT blinding tweak than the 2-of-2 spending path, so the mint cannot correlate Alice’s refund to the normal channel close.

Source

pub fn get_sender_blinded_secret_key_for_stage1_refund( &self, alice_secret: &SecretKey, ) -> Result<SecretKey>

Derive the blinded sender secret key for stage 1 expiry refund

Uses a DIFFERENT blinding tweak than the 2-of-2 spending path. Alice uses this to sign when reclaiming funds after expiry.

Source

pub fn get_receiver_blinded_secret_key_for_stage1( &self, charlie_secret: &SecretKey, ) -> Result<SecretKey>

Derive the blinded receiver secret key for stage 1 signing

For P2BK, Charlie must sign with a blinded private key k such that k*G = P’. This handles BIP-340 parity: if Charlie’s pubkey has odd Y, we negate his private key before adding the blinding scalar.

Source

pub fn get_sender_blinded_pubkey_for_stage2_output( &self, amount: u64, index: usize, ) -> Result<PublicKey>

Get the blinded sender (Alice) pubkey for a specific stage 2 output

Used for stage 1 outputs - each of Alice’s proofs is locked to a UNIQUE blinded pubkey derived from (amount, index). She’ll need to sign with the corresponding secret key in stage 2.

This provides better privacy than a shared pubkey - the mint cannot trivially link proofs from the same channel closure.

Source

pub fn get_receiver_blinded_pubkey_for_stage2_output( &self, amount: u64, index: usize, ) -> Result<PublicKey>

Get the blinded receiver (Charlie) pubkey for a specific stage 2 output

Used for stage 1 outputs - each of Charlie’s proofs is locked to a UNIQUE blinded pubkey derived from (amount, index). He’ll need to sign with the corresponding secret key in stage 2.

This provides better privacy than a shared pubkey - the mint cannot trivially link proofs from the same channel closure.

Source

pub fn get_sender_blinded_secret_key_for_stage2_output( &self, alice_secret: &SecretKey, amount: u64, index: usize, ) -> Result<SecretKey>

Derive the blinded sender secret key for a specific stage 2 output

Alice uses this to sign when spending a specific stage 1 proof in stage 2. Each proof has a unique blinded secret key derived from (amount, index).

Source

pub fn get_receiver_blinded_secret_key_for_stage2_output( &self, charlie_secret: &SecretKey, amount: u64, index: usize, ) -> Result<SecretKey>

Derive the blinded receiver secret key for a specific stage 2 output

Charlie uses this to sign when spending a specific stage 1 proof in stage 2. Each proof has a unique blinded secret key derived from (amount, index).

Source

pub fn unit_name(&self) -> &str

Get a string representation of the unit

Source

pub fn get_stage2_blinded_pubkey_for_stage1_output( &self, context: &str, amount: u64, index: usize, ) -> Result<PublicKey, Error>

Get the STAGE2 blinded pubkey for a stage 1 output context (“sender” or “receiver”)

Returns the stage2 blinded pubkey for use in stage 1 commitment outputs:

  • “receiver” → Charlie’s per-proof blinded pubkey (stage2 context)
  • “sender” → Alice’s per-proof blinded pubkey (stage2 context)
  • “funding” → error (funding uses 2-of-2 with stage1 blinded pubkeys)

Uses “stage2” blinding context because these are the keys needed to sign in stage 2. Each proof gets a UNIQUE blinded pubkey derived from (amount, index) for better privacy.

Source

pub fn create_deterministic_output_with_blinding( &self, context: &str, amount: u64, index: usize, ) -> Result<DeterministicSecretWithBlinding, Error>

Create a deterministic output with blinding using the channel ID and channel secret Uses channel_secret, channel_id, context, amount, and index in the derivation per NUT-XX spec

The context parameter specifies the role: “sender”, “receiver”, or “funding”

  • “sender”/“receiver” create simple P2PK outputs for commitments using stage2 blinded pubkeys
  • “funding” creates P2PK outputs with 2-of-2 multisig + expiry conditions
Source

pub fn get_minimum_funding_token_amount( capacity: u64, keyset_info: &KeysetInfo, maximum_amount_for_one_output: u64, ) -> Result<u64>

Get the minimum funding token amount for a given capacity using double inverse

This computes the minimum funding_token_amount needed to achieve at least the specified capacity after both fee stages, using the given keyset.

Applies the inverse fee calculation twice to the capacity:

  1. capacity → post-stage-1 nominal (accounting for stage 2 fees)
  2. post-stage-1 nominal → funding token nominal (accounting for stage 1 fees)
Source

pub fn get_total_funding_token_amount(&self) -> Result<u64>

Get the total funding token amount

Returns the explicit funding_token_amount field.

Source

pub fn get_value_after_stage1_with_keyset( &self, keyset_info: &KeysetInfo, ) -> Result<u64>

Get the value available after stage 1 fees with a specific keyset

Source

pub fn get_value_after_stage1(&self) -> Result<u64>

Get the value available after stage 1 fees

Takes the funding token amount and applies the forward fee calculation to determine the actual amount available after the swap transaction (stage 1).

This represents the total amount that will be distributed between Alice and Charlie in the commitment transaction outputs.

Returns the actual value after stage 1 fees

Source

pub fn get_de_facto_balance(&self, intended_balance: u64) -> Result<u64>

Compute the actual de facto balance from an intended balance

Due to output denomination constraints and fee rounding, the actual balance that can be created may differ slightly from the intended balance.

This method:

  1. Applies inverse to find the nominal value needed for the intended balance
  2. Applies deterministic_value to that nominal to get the actual de facto balance

Returns the actual balance that will be created

Source§

impl ChannelParameters

Source

pub fn new( sender_pubkey: PublicKey, receiver_pubkey: PublicKey, mint: String, unit: CurrencyUnit, capacity: u64, funding_token_amount: u64, expiry_timestamp: u64, setup_timestamp: u64, keyset_info: KeysetInfo, maximum_amount_for_one_output: u64, channel_secret: [u8; 32], ) -> Result<Self>

Create new channel parameters with a pre-computed channel secret

Source

pub fn new_with_secret_key( sender_pubkey: PublicKey, receiver_pubkey: PublicKey, mint: String, unit: CurrencyUnit, capacity: u64, funding_token_amount: u64, expiry_timestamp: u64, setup_timestamp: u64, keyset_info: KeysetInfo, maximum_amount_for_one_output: u64, my_secret: &SecretKey, ) -> Result<Self>

Create new channel parameters by computing the channel secret from a secret key

This constructor computes the channel secret (hashed ECDH) automatically. It auto-detects whether the provided secret key belongs to Alice or Charlie by checking if its public key matches either party, then uses the counterparty’s public key for ECDH.

§Arguments
  • my_secret - Either Alice’s or Charlie’s secret key
  • All other arguments are the same as new
§Errors

Returns an error if the secret key’s public key doesn’t match either sender_pubkey or receiver_pubkey

Source

pub fn from_json_with_secret_key( json_str: &str, keyset_info: KeysetInfo, my_secret: &SecretKey, ) -> Result<Self>

Create channel parameters from a JSON string and a secret key

The JSON should contain: mint, unit, capacity, keyset_id, input_fee_ppk, maximum_amount, setup_timestamp, sender_pubkey, receiver_pubkey, expiry_timestamp (as produced by get_channel_id_params_json)

Additional parameters needed:

  • keyset_info - Keyset information from the mint (keyset_id and input_fee_ppk must match JSON)
  • my_secret - Either Alice’s or Charlie’s secret key for ECDH
Source

pub fn from_json_with_channel_secret( json_str: &str, keyset_info: KeysetInfo, channel_secret: [u8; 32], ) -> Result<Self>

Create channel parameters from a JSON string with a pre-computed channel secret

Same as from_json but takes the channel secret directly instead of computing it.

Source

pub fn get_capacity(&self) -> u64

Get channel capacity Returns the maximum final value (after both fee stages) that Charlie can receive

Source

pub fn get_channel_id_bytes(&self) -> [u8; 32]

Get channel ID as raw bytes (32-byte SHA256 hash) The hash is computed over: mint|unit|capacity|funding_token_amount|keyset_id|input_fee_ppk|maximum_amount|setup_timestamp|sender_pubkey|receiver_pubkey|expiry_timestamp|channel_secret

The channel_secret (channel_secret) is included implicitly — it does not appear in get_channel_id_params_json(). This means the channel ID can only be computed by the two parties who know the channel secret.

Source

pub fn get_channel_id(&self) -> String

Get channel ID as a hex string

Source

pub fn get_channel_id_params_json(&self) -> String

Get a JSON string representation of the data that contributes to the channel ID This includes all parameters that define the channel unique identity.

Trait Implementations§

Source§

impl Clone for ChannelParameters

Source§

fn clone(&self) -> ChannelParameters

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ChannelParameters

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ChannelParameters

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ChannelParameters

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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