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: PublicKeyAlice’s public key (sender)
receiver_pubkey: PublicKeyCharlie’s public key (receiver)
mint: StringMint URL (or “local” for in-process mint)
unit: CurrencyUnitCurrency unit for the channel
capacity: u64Channel capacity: maximum final value (after both fee stages) that Charlie can receive
funding_token_amount: u64Total nominal value of the funding token (must satisfy: capacity <= forward(forward(funding_token_amount)))
expiry_timestamp: u64Expiry timestamp after which Alice can reclaim funds (unix timestamp)
setup_timestamp: u64Setup timestamp (unix timestamp when channel was created)
keyset_info: KeysetInfoKeyset information (ID, keys, amounts, fees)
maximum_amount_for_one_output: u64Maximum 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
impl ChannelParameters
Sourcepub fn get_sender_blinded_pubkey_for_stage1(&self) -> Result<PublicKey>
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)
Sourcepub fn get_receiver_blinded_pubkey_for_stage1(&self) -> Result<PublicKey>
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)
Sourcepub fn get_sender_blinded_secret_key_for_stage1(
&self,
alice_secret: &SecretKey,
) -> Result<SecretKey>
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.
Sourcepub fn derive_sender_blinding_scalar_for_stage1(&self) -> Result<Scalar>
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.
Sourcepub fn derive_receiver_blinding_scalar_for_stage1(&self) -> Result<Scalar>
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.
Sourcepub fn get_sender_blinded_pubkey_for_stage1_refund(&self) -> Result<PublicKey>
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.
Sourcepub fn get_sender_blinded_secret_key_for_stage1_refund(
&self,
alice_secret: &SecretKey,
) -> Result<SecretKey>
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.
Sourcepub fn get_receiver_blinded_secret_key_for_stage1(
&self,
charlie_secret: &SecretKey,
) -> Result<SecretKey>
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.
Sourcepub fn get_sender_blinded_pubkey_for_stage2_output(
&self,
amount: u64,
index: usize,
) -> Result<PublicKey>
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.
Sourcepub fn get_receiver_blinded_pubkey_for_stage2_output(
&self,
amount: u64,
index: usize,
) -> Result<PublicKey>
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.
Sourcepub fn get_sender_blinded_secret_key_for_stage2_output(
&self,
alice_secret: &SecretKey,
amount: u64,
index: usize,
) -> Result<SecretKey>
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).
Sourcepub fn get_receiver_blinded_secret_key_for_stage2_output(
&self,
charlie_secret: &SecretKey,
amount: u64,
index: usize,
) -> Result<SecretKey>
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).
Sourcepub fn get_stage2_blinded_pubkey_for_stage1_output(
&self,
context: &str,
amount: u64,
index: usize,
) -> Result<PublicKey, Error>
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.
Sourcepub fn create_deterministic_output_with_blinding(
&self,
context: &str,
amount: u64,
index: usize,
) -> Result<DeterministicSecretWithBlinding, Error>
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
Sourcepub fn get_minimum_funding_token_amount(
capacity: u64,
keyset_info: &KeysetInfo,
maximum_amount_for_one_output: u64,
) -> Result<u64>
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:
- capacity → post-stage-1 nominal (accounting for stage 2 fees)
- post-stage-1 nominal → funding token nominal (accounting for stage 1 fees)
Sourcepub fn get_total_funding_token_amount(&self) -> Result<u64>
pub fn get_total_funding_token_amount(&self) -> Result<u64>
Get the total funding token amount
Returns the explicit funding_token_amount field.
Sourcepub fn get_value_after_stage1_with_keyset(
&self,
keyset_info: &KeysetInfo,
) -> Result<u64>
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
Sourcepub fn get_value_after_stage1(&self) -> Result<u64>
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
Sourcepub fn get_de_facto_balance(&self, intended_balance: u64) -> Result<u64>
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:
- Applies inverse to find the nominal value needed for the intended balance
- Applies deterministic_value to that nominal to get the actual de facto balance
Returns the actual balance that will be created
Source§impl ChannelParameters
impl ChannelParameters
Sourcepub 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>
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
Sourcepub 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>
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
Sourcepub fn from_json_with_secret_key(
json_str: &str,
keyset_info: KeysetInfo,
my_secret: &SecretKey,
) -> Result<Self>
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
Sourcepub fn from_json_with_channel_secret(
json_str: &str,
keyset_info: KeysetInfo,
channel_secret: [u8; 32],
) -> Result<Self>
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.
Sourcepub fn get_capacity(&self) -> u64
pub fn get_capacity(&self) -> u64
Get channel capacity Returns the maximum final value (after both fee stages) that Charlie can receive
Sourcepub fn get_channel_id_bytes(&self) -> [u8; 32]
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.
Sourcepub fn get_channel_id(&self) -> String
pub fn get_channel_id(&self) -> String
Get channel ID as a hex string
Sourcepub fn get_channel_id_params_json(&self) -> String
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
impl Clone for ChannelParameters
Source§fn clone(&self) -> ChannelParameters
fn clone(&self) -> ChannelParameters
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more