diff --git a/zcash_proofs/src/lib.rs b/zcash_proofs/src/lib.rs index 157643079..ab9da1ba3 100644 --- a/zcash_proofs/src/lib.rs +++ b/zcash_proofs/src/lib.rs @@ -135,7 +135,10 @@ pub fn load_parameters( ) } -fn parse_parameters( +/// Parse Bls12 keys from bytes as serialized by [`Parameters::write`]. +/// +/// This function will panic if it encounters unparseable data. +pub fn parse_parameters( spend_fs: R, output_fs: R, sprout_fs: Option, diff --git a/zcash_proofs/src/prover.rs b/zcash_proofs/src/prover.rs index f84b22279..2c6fd2716 100644 --- a/zcash_proofs/src/prover.rs +++ b/zcash_proofs/src/prover.rs @@ -2,6 +2,7 @@ use bellman::groth16::{Parameters, PreparedVerifyingKey}; use bls12_381::Bls12; +use std::path::Path; use zcash_primitives::{ merkle_tree::MerklePath, primitives::{Diversifier, PaymentAddress, ProofGenerationKey, Rseed}, @@ -11,15 +12,10 @@ use zcash_primitives::{ transaction::components::{Amount, GROTH_PROOF_SIZE}, }; -use crate::sapling::SaplingProvingContext; +use crate::{load_parameters, parse_parameters, sapling::SaplingProvingContext}; #[cfg(feature = "local-prover")] -use crate::{default_params_folder, load_parameters, SAPLING_OUTPUT_NAME, SAPLING_SPEND_NAME}; -#[cfg(feature = "local-prover")] -use std::path::Path; - -#[cfg(feature = "bundled-prover")] -use crate::parse_parameters; +use crate::{default_params_folder, SAPLING_OUTPUT_NAME, SAPLING_SPEND_NAME}; /// An implementation of [`TxProver`] using Sapling Spend and Output parameters from /// locally-accessible paths. @@ -48,8 +44,6 @@ impl LocalTxProver { /// /// This function will panic if the paths do not point to valid parameter files with /// the expected hashes. - #[cfg(feature = "local-prover")] - #[cfg_attr(docsrs, doc(cfg(feature = "local-prover")))] pub fn new(spend_path: &Path, output_path: &Path) -> Self { let (spend_params, spend_vk, output_params, _, _) = load_parameters(spend_path, output_path, None); @@ -60,6 +54,32 @@ impl LocalTxProver { } } + /// Creates a `LocalTxProver` using parameters specified as byte arrays. + /// + /// # Examples + /// + /// ```should_panic + /// use std::path::Path; + /// use zcash_proofs::prover::LocalTxProver; + /// + /// let tx_prover = LocalTxProver::from_bytes(&[0u8], &[0u8]); + /// ``` + /// + /// # Panics + /// + /// This function will panic if the byte arrays do not contain valid parameters with + /// the expected hashes. + pub fn from_bytes(spend_param_bytes: &[u8], output_param_bytes: &[u8]) -> Self { + let (spend_params, spend_vk, output_params, _, _) = + parse_parameters(spend_param_bytes, output_param_bytes, None); + + LocalTxProver { + spend_params, + spend_vk, + output_params, + } + } + /// Attempts to create a `LocalTxProver` using parameters from the default local /// location. ///