mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-17 15:21:39 +02:00
Expose mwixnet onion crypto for the swap server
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.
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
//! Onion modules for mxmixnet
|
||||
mod onion;
|
||||
pub mod onion;
|
||||
mod types;
|
||||
|
||||
pub use onion::{
|
||||
|
||||
@@ -68,7 +68,6 @@ impl AsRef<PublicKey> for DalekPublicKey {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
/// Serializes an Option<DalekPublicKey> to and from hex
|
||||
pub mod option_dalek_pubkey_serde {
|
||||
use super::DalekPublicKey;
|
||||
@@ -148,7 +147,6 @@ impl AsRef<Signature> 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<DalekSignature, DalekError> {
|
||||
use ed25519_dalek::{Keypair, Signer};
|
||||
let secret =
|
||||
|
||||
@@ -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<R: Reader>(reader: &mut R) -> Result<SecretKey, ser::Erro
|
||||
}
|
||||
|
||||
/// Build a Pedersen Commitment using the provided value and blinding factor
|
||||
#[cfg(test)]
|
||||
pub fn commit(value: u64, blind: &SecretKey) -> Result<Commitment, secp256k1zkp::Error> {
|
||||
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<Commitment, secp
|
||||
}
|
||||
|
||||
/// Signs the message with the provided SecretKey
|
||||
#[cfg(test)]
|
||||
#[allow(dead_code)]
|
||||
pub fn sign(
|
||||
sk: &SecretKey,
|
||||
msg: &grin_util::secp::Message,
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
//! Onion module definition
|
||||
|
||||
mod crypto;
|
||||
pub mod crypto;
|
||||
pub mod onion;
|
||||
pub mod util;
|
||||
|
||||
@@ -48,7 +48,7 @@ pub struct Hop {
|
||||
}
|
||||
|
||||
/// Crate a new hop
|
||||
#[cfg(test)]
|
||||
#[cfg(any(test, feature = "test-helpers"))]
|
||||
pub fn new_hop(
|
||||
server_key: &SecretKey,
|
||||
hop_excess: &SecretKey,
|
||||
@@ -117,9 +117,9 @@ pub fn create_onion(
|
||||
Ok(onion)
|
||||
}
|
||||
|
||||
/// Internal tests
|
||||
/// Onion test helpers (random onions, commitments, proofs, keypairs).
|
||||
#[allow(missing_docs, dead_code)]
|
||||
#[cfg(test)]
|
||||
#[cfg(any(test, feature = "test-helpers"))]
|
||||
pub mod test_util {
|
||||
use super::*;
|
||||
use crypto::dalek::DalekPublicKey;
|
||||
|
||||
Reference in New Issue
Block a user