From ce779188b19e949e3837f80eeaf73c31f61e17c0 Mon Sep 17 00:00:00 2001 From: jwinterm Date: Thu, 4 Jun 2026 13:08:16 -0400 Subject: [PATCH] Expose mwixnet onion crypto for the swap server MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The mwixnet swap server consumes the onion primitives from this crate (mimblewimble/mwixnet re-imports them rather than vendoring its own). Master's #726 mwixnet kept onion/crypto private and several helpers test-only — fine for the wallet, but the server needs them. - Make mwixnet::onion and onion::crypto public. - Un-gate the crypto the server uses in production: secp::{commit, sign}, dalek::{sign, option_dalek_pubkey_serde, dalek_sig_serde}; re-export RangeProof. - Gate the test-only helpers (new_hop, test_util) behind a new `test-helpers` feature, off by default, so the server's tests can use them. --- libwallet/Cargo.toml | 5 +++++ libwallet/src/mwixnet/mod.rs | 2 +- libwallet/src/mwixnet/onion/crypto/dalek.rs | 3 --- libwallet/src/mwixnet/onion/crypto/secp.rs | 5 +---- libwallet/src/mwixnet/onion/mod.rs | 8 ++++---- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/libwallet/Cargo.toml b/libwallet/Cargo.toml index 336fad0..b13c681 100644 --- a/libwallet/Cargo.toml +++ b/libwallet/Cargo.toml @@ -10,6 +10,11 @@ exclude = ["**/*.grin", "**/*.grin2"] #build = "src/build/build.rs" edition = "2021" +[features] +# Exposes the mwixnet onion test helpers (test_util, new_hop) to downstream +# crates such as the mwixnet swap server. Off by default; not part of normal builds. +test-helpers = [] + [dependencies] blake2-rfc = "0.2" rand = "0.6" diff --git a/libwallet/src/mwixnet/mod.rs b/libwallet/src/mwixnet/mod.rs index 0605265..ebc5a9c 100644 --- a/libwallet/src/mwixnet/mod.rs +++ b/libwallet/src/mwixnet/mod.rs @@ -13,7 +13,7 @@ // limitations under the License. //! Onion modules for mxmixnet -mod onion; +pub mod onion; mod types; pub use onion::{ diff --git a/libwallet/src/mwixnet/onion/crypto/dalek.rs b/libwallet/src/mwixnet/onion/crypto/dalek.rs index 38fd408..8f43ce4 100644 --- a/libwallet/src/mwixnet/onion/crypto/dalek.rs +++ b/libwallet/src/mwixnet/onion/crypto/dalek.rs @@ -68,7 +68,6 @@ impl AsRef for DalekPublicKey { } } -#[cfg(test)] /// Serializes an Option to and from hex pub mod option_dalek_pubkey_serde { use super::DalekPublicKey; @@ -148,7 +147,6 @@ impl AsRef for DalekSignature { } /// Serializes a DalekSignature to and from hex -#[cfg(test)] pub mod dalek_sig_serde { use super::DalekSignature; use grin_util::ToHex; @@ -176,7 +174,6 @@ pub mod dalek_sig_serde { /// Dalek signature sign wrapper // TODO: This is likely duplicated throughout crate, check -#[cfg(test)] pub fn sign(sk: &SecretKey, message: &[u8]) -> Result { use ed25519_dalek::{Keypair, Signer}; let secret = diff --git a/libwallet/src/mwixnet/onion/crypto/secp.rs b/libwallet/src/mwixnet/onion/crypto/secp.rs index eda6abe..26566be 100644 --- a/libwallet/src/mwixnet/onion/crypto/secp.rs +++ b/libwallet/src/mwixnet/onion/crypto/secp.rs @@ -18,7 +18,7 @@ pub use grin_util::secp::{ self as secp256k1zkp, constants::SECRET_KEY_SIZE, key::{SecretKey, ZERO_KEY}, - pedersen::Commitment, + pedersen::{Commitment, RangeProof}, rand::thread_rng, ContextFlag, Secp256k1, }; @@ -47,7 +47,6 @@ pub fn read_secret_key(reader: &mut R) -> Result Result { let secp = Secp256k1::with_caps(ContextFlag::Commit); let commit = secp.commit(value, blind.clone())?; @@ -76,8 +75,6 @@ pub fn sub_value(commitment: &Commitment, value: u64) -> Result