Skip to content

Commit 98c87d9

Browse files
authored
Merge pull request #41 from eigerco/feat/in-memory-api
feat(sdk): in-memory api
2 parents ef455db + 2628318 commit 98c87d9

File tree

29 files changed

+1731
-520
lines changed

29 files changed

+1731
-520
lines changed

Cargo.lock

Lines changed: 335 additions & 256 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/zair-cli/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ clap = { workspace = true, features = ["derive", "env"] }
1919
console-subscriber = { workspace = true, optional = true }
2020
dotenvy = { workspace = true }
2121
eyre = { workspace = true }
22-
rustls = { workspace = true, features = ["ring"] }
2322
tokio = { workspace = true, features = [
2423
"rt-multi-thread",
2524
"macros",

crates/zair-cli/src/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ fn init_tracing() -> eyre::Result<()> {
4949
)]
5050
async fn main() -> eyre::Result<()> {
5151
// Initialize rustls crypto provider (required for TLS connections)
52-
rustls::crypto::ring::default_provider()
53-
.install_default()
54-
.map_err(|e| eyre::eyre!("Failed to install rustls crypto provider: {e:?}"))?;
52+
zair_sdk::install_default_crypto_provider()?;
5553

5654
// Load .env file (fails silently if not found)
5755
let _ = dotenvy::dotenv();

crates/zair-nonmembership/src/pool/sapling.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn map_sapling_user_positions(
2525

2626
/// # Errors
2727
/// Returns an error if `gap_idx` is out of bounds for the given nullifiers.
28-
pub fn sapling_gap_bounds(
28+
pub const fn sapling_gap_bounds(
2929
nullifiers: &[Nullifier],
3030
gap_idx: usize,
3131
) -> Result<(Nullifier, Nullifier), MerklePathError> {

crates/zair-nonmembership/src/sparse/sapling.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ mod tests {
465465
}};
466466
}
467467

468-
fn make_leaf(value: u8) -> NonMembershipNode {
468+
const fn make_leaf(value: u8) -> NonMembershipNode {
469469
let mut bytes = [0u8; 32];
470470
bytes[0] = value;
471471
NonMembershipNode::new(bytes)

crates/zair-orchard-proofs/src/instance.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,19 @@ const NATIVE_INSTANCE_COUNT: usize = 7;
1212
/// Number of public instance scalars for the SHA-256 value commitment scheme.
1313
const SHA256_INSTANCE_COUNT: usize = 13;
1414

15-
pub(crate) fn base_from_repr(bytes: [u8; 32]) -> Result<pallas::Base, ClaimProofError> {
15+
pub fn base_from_repr(bytes: [u8; 32]) -> Result<pallas::Base, ClaimProofError> {
1616
Option::<pallas::Base>::from(pallas::Base::from_repr(bytes))
1717
.ok_or(ClaimProofError::NonCanonicalBase)
1818
}
1919

2020
#[cfg(feature = "prove")]
21-
pub(crate) fn scalar_from_repr(bytes: [u8; 32]) -> Result<pallas::Scalar, ClaimProofError> {
21+
pub fn scalar_from_repr(bytes: [u8; 32]) -> Result<pallas::Scalar, ClaimProofError> {
2222
Option::<pallas::Scalar>::from(pallas::Scalar::from_repr(bytes))
2323
.ok_or(ClaimProofError::NonCanonicalScalar)
2424
}
2525

2626
#[cfg(feature = "prove")]
27-
pub(crate) fn target_id_slice(
28-
target_id: &[u8; 32],
29-
target_id_len: u8,
30-
) -> Result<&[u8], ClaimProofError> {
27+
pub fn target_id_slice(target_id: &[u8; 32], target_id_len: u8) -> Result<&[u8], ClaimProofError> {
3128
let target = target_id
3229
.get(..usize::from(target_id_len))
3330
.ok_or(ClaimProofError::InvalidTargetIdLength)?;
@@ -36,7 +33,7 @@ pub(crate) fn target_id_slice(
3633
}
3734

3835
#[cfg(feature = "prove")]
39-
pub(crate) fn point_from_bytes(bytes: [u8; 32]) -> Result<pallas::Affine, ClaimProofError> {
36+
pub fn point_from_bytes(bytes: [u8; 32]) -> Result<pallas::Affine, ClaimProofError> {
4037
let p = Option::<pallas::Point>::from(pallas::Point::from_bytes(&bytes))
4138
.ok_or(ClaimProofError::InvalidPoint)?;
4239
if bool::from(p.is_identity()) {
@@ -57,7 +54,7 @@ fn coords_or_zero(p: pallas::Point) -> (pallas::Base, pallas::Base) {
5754
}
5855
}
5956

60-
pub(crate) fn to_instance(
57+
pub fn to_instance(
6158
note_commitment_root: [u8; 32],
6259
cv: Option<[u8; 32]>,
6360
cv_sha256: Option<[u8; 32]>,

crates/zair-orchard-proofs/src/keys.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::error::ClaimProofError;
1313
use crate::types::ValueCommitmentScheme;
1414

1515
#[derive(Debug)]
16-
pub(crate) struct Keys {
16+
pub struct Keys {
1717
pub(crate) vk: VerifyingKey<vesta::Affine>,
1818
#[cfg_attr(feature = "verify", allow(dead_code))]
1919
pub(crate) pk: plonk::ProvingKey<vesta::Affine>,
@@ -51,7 +51,7 @@ struct CacheKey {
5151
target_id_len: u8,
5252
}
5353

54-
pub(crate) fn keys_for(
54+
pub fn keys_for(
5555
params: &Params<vesta::Affine>,
5656
scheme: ValueCommitmentScheme,
5757
target_id: [u8; 32],

crates/zair-sapling-proofs/src/prover/builder.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,23 @@ pub fn load_parameters(
121121

122122
Ok(ClaimParameters(params))
123123
}
124+
125+
/// Load parameters from in-memory bytes.
126+
///
127+
/// # Arguments
128+
/// * `bytes` - Proving key bytes
129+
/// * `checked` - If true, verify the parameters (slower but safer)
130+
///
131+
/// # Errors
132+
/// Returns an error if reading or parsing fails.
133+
pub fn load_parameters_from_bytes(
134+
bytes: &[u8],
135+
checked: bool,
136+
) -> Result<ClaimParameters, ParameterError> {
137+
let cursor = std::io::Cursor::new(bytes);
138+
let reader = std::io::BufReader::new(cursor);
139+
140+
let params = Parameters::read(reader, checked).map_err(ParameterError::Deserialization)?;
141+
142+
Ok(ClaimParameters(params))
143+
}

crates/zair-sapling-proofs/src/prover/convenience.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub fn bytes_less_than(a: &[u8; 32], b: &[u8; 32]) -> bool {
6767
/// Returns an error if proof generation fails.
6868
#[allow(
6969
clippy::too_many_lines,
70+
clippy::similar_names,
7071
reason = "End-to-end witness preparation and proving"
7172
)]
7273
pub fn generate_claim_proof(

crates/zair-sapling-proofs/src/prover/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ mod builder;
55
mod convenience;
66
mod proving;
77

8-
pub use builder::{ParameterError, generate_parameters, load_parameters, save_parameters};
8+
pub use builder::{
9+
ParameterError, generate_parameters, load_parameters, load_parameters_from_bytes,
10+
save_parameters,
11+
};
912
pub use convenience::generate_claim_proof;
1013
pub use proving::ClaimParameters;
1114

0 commit comments

Comments
 (0)