Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pczt: Add a Redactor role #1670

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pczt/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this library adheres to Rust's notion of

## [Unreleased]

### Added
- `pczt::roles::redactor`

### Changed
- Migrated to `nonempty 0.11`

Expand Down
5 changes: 5 additions & 0 deletions pczt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
//! - Updater (anyone can contribute)
//! - Adds information necessary for subsequent entities to proceed, such as key paths
//! for signing spends.
//! - Redactor (anyone can execute)
//! - Removes information that is unnecessary for subsequent entities to proceed.
//! - This can be useful e.g. when creating a transaction that has inputs from multiple
//! independent Signers; each can receive a PCZT with just the information they need
//! to sign, but (e.g.) not the `alpha` values for other Signers.
//! - Prover (capability holders can contribute)
//! - Needs all private information for a single spend or output.
//! - In practice, the Updater that adds a given spend or output will either act as
Expand Down
2 changes: 2 additions & 0 deletions pczt/src/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub mod verifier;

pub mod updater;

pub mod redactor;

#[cfg(feature = "prover")]
pub mod prover;

Expand Down
45 changes: 45 additions & 0 deletions pczt/src/roles/redactor/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use crate::{common::Global, Pczt};

pub mod orchard;
pub mod sapling;
pub mod transparent;

pub struct Redactor {
pczt: Pczt,
}

impl Redactor {
/// Instantiates the Redactor role with the given PCZT.
pub fn new(pczt: Pczt) -> Self {

Check warning on line 13 in pczt/src/roles/redactor/mod.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/mod.rs#L13

Added line #L13 was not covered by tests
Self { pczt }
}

/// Redacts the global transaction details with the given closure.
pub fn redact_global_with<F>(mut self, f: F) -> Self

Check warning on line 18 in pczt/src/roles/redactor/mod.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/mod.rs#L18

Added line #L18 was not covered by tests
where
F: FnOnce(GlobalRedactor<'_>),
{
f(GlobalRedactor(&mut self.pczt.global));
self

Check warning on line 23 in pczt/src/roles/redactor/mod.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/mod.rs#L22-L23

Added lines #L22 - L23 were not covered by tests
}

/// Finishes the Redactor role, returning the redacted PCZT.
pub fn finish(self) -> Pczt {
self.pczt

Check warning on line 28 in pczt/src/roles/redactor/mod.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/mod.rs#L27-L28

Added lines #L27 - L28 were not covered by tests
}
}

/// An Redactor for the global transaction details.
pub struct GlobalRedactor<'a>(&'a mut Global);

impl<'a> GlobalRedactor<'a> {
/// Redacts the proprietary value at the given key.
pub fn redact_proprietary(&mut self, key: &str) {
self.0.proprietary.remove(key);

Check warning on line 38 in pczt/src/roles/redactor/mod.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/mod.rs#L37-L38

Added lines #L37 - L38 were not covered by tests
}

/// Removes all proprietary values.
pub fn clear_proprietary(&mut self) {
self.0.proprietary.clear();

Check warning on line 43 in pczt/src/roles/redactor/mod.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/mod.rs#L42-L43

Added lines #L42 - L43 were not covered by tests
}
}
222 changes: 222 additions & 0 deletions pczt/src/roles/redactor/orchard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
use crate::orchard::{Action, Bundle};

impl super::Redactor {
/// Redacts the Orchard bundle with the given closure.
pub fn redact_orchard_with<F>(mut self, f: F) -> Self

Check warning on line 5 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L5

Added line #L5 was not covered by tests
where
F: FnOnce(OrchardRedactor<'_>),
{
f(OrchardRedactor(&mut self.pczt.orchard));
self

Check warning on line 10 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L9-L10

Added lines #L9 - L10 were not covered by tests
}
}

/// A Redactor for the Orchard bundle.
pub struct OrchardRedactor<'a>(&'a mut Bundle);

impl<'a> OrchardRedactor<'a> {
/// Redacts all actions in the same way.
pub fn redact_actions<F>(&mut self, f: F)

Check warning on line 19 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L19

Added line #L19 was not covered by tests
where
F: FnOnce(ActionRedactor<'_>),
{
f(ActionRedactor(Actions::All(&mut self.0.actions)));

Check warning on line 23 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L23

Added line #L23 was not covered by tests
}

/// Redacts the action at the given index.
///
/// Does nothing if the index is out of range.
pub fn redact_action<F>(&mut self, index: usize, f: F)

Check warning on line 29 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L29

Added line #L29 was not covered by tests
where
F: FnOnce(ActionRedactor<'_>),
{
if let Some(action) = self.0.actions.get_mut(index) {
f(ActionRedactor(Actions::One(action)));

Check warning on line 34 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L33-L34

Added lines #L33 - L34 were not covered by tests
}
}

/// Removes the proof.
pub fn clear_zkproof(&mut self) {
self.0.zkproof = None;

Check warning on line 40 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L39-L40

Added lines #L39 - L40 were not covered by tests
}

/// Removes the proof.
pub fn clear_bsk(&mut self) {
self.0.bsk = None;

Check warning on line 45 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L44-L45

Added lines #L44 - L45 were not covered by tests
}
}

/// A Redactor for Orchard actions.
pub struct ActionRedactor<'a>(Actions<'a>);

enum Actions<'a> {
All(&'a mut [Action]),
One(&'a mut Action),
}

impl<'a> ActionRedactor<'a> {
fn redact<F>(&mut self, f: F)

Check warning on line 58 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L58

Added line #L58 was not covered by tests
where
F: Fn(&mut Action),
{
match &mut self.0 {
Actions::All(actions) => {
for action in actions.iter_mut() {
f(action);

Check warning on line 65 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L62-L65

Added lines #L62 - L65 were not covered by tests
}
}
Actions::One(action) => {
f(action);

Check warning on line 69 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L68-L69

Added lines #L68 - L69 were not covered by tests
}
}
}

/// Removes the spend authorizing signature.
pub fn clear_spend_auth_sig(&mut self) {
self.redact(|action| {
action.spend.spend_auth_sig = None;

Check warning on line 77 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L75-L77

Added lines #L75 - L77 were not covered by tests
});
}

/// Removes the spend's recipient.
pub fn clear_spend_recipient(&mut self) {
self.redact(|action| {
action.spend.recipient = None;

Check warning on line 84 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L82-L84

Added lines #L82 - L84 were not covered by tests
});
}

/// Removes the spend's value.
pub fn clear_spend_value(&mut self) {
self.redact(|action| {
action.spend.value = None;

Check warning on line 91 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L89-L91

Added lines #L89 - L91 were not covered by tests
});
}

/// Removes the rho value for the note being spent.
pub fn clear_spend_rho(&mut self) {
self.redact(|action| {
action.spend.rho = None;

Check warning on line 98 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L96-L98

Added lines #L96 - L98 were not covered by tests
});
}

/// Removes the seed randomness for the note being spent.
pub fn clear_spend_rseed(&mut self) {
self.redact(|action| {
action.spend.rseed = None;

Check warning on line 105 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L103-L105

Added lines #L103 - L105 were not covered by tests
});
}

/// Removes the spend's full viewing key.
pub fn clear_spend_fvk(&mut self) {
self.redact(|action| {
action.spend.fvk = None;

Check warning on line 112 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L110-L112

Added lines #L110 - L112 were not covered by tests
});
}

/// Removes the witness from the spent note to the bundle's anchor.
pub fn clear_spend_witness(&mut self) {
self.redact(|action| {
action.spend.witness = None;

Check warning on line 119 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L117-L119

Added lines #L117 - L119 were not covered by tests
});
}

/// Removes the spend authorization randomizer.
pub fn clear_spend_alpha(&mut self) {
self.redact(|action| {
action.spend.alpha = None;

Check warning on line 126 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L124-L126

Added lines #L124 - L126 were not covered by tests
});
}

/// Removes the ZIP 32 derivation path at which the spending key can be found for the
/// note being spent.
pub fn clear_spend_zip32_derivation(&mut self) {
self.redact(|action| {
action.spend.zip32_derivation = None;

Check warning on line 134 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L132-L134

Added lines #L132 - L134 were not covered by tests
});
}

/// Removes the spending key for this spent note, if it is a dummy note.
pub fn clear_spend_dummy_sk(&mut self) {
self.redact(|action| {
action.spend.dummy_sk = None;

Check warning on line 141 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L139-L141

Added lines #L139 - L141 were not covered by tests
});
}

/// Redacts the spend-specific proprietary value at the given key.
pub fn redact_spend_proprietary(&mut self, key: &str) {
self.redact(|action| {
action.spend.proprietary.remove(key);

Check warning on line 148 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L146-L148

Added lines #L146 - L148 were not covered by tests
});
}

/// Removes all spend-specific proprietary values.
pub fn clear_spend_proprietary(&mut self) {
self.redact(|action| {
action.spend.proprietary.clear();

Check warning on line 155 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L153-L155

Added lines #L153 - L155 were not covered by tests
});
}

/// Removes the output's recipient.
pub fn clear_output_recipient(&mut self) {
self.redact(|action| {
action.output.recipient = None;

Check warning on line 162 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L160-L162

Added lines #L160 - L162 were not covered by tests
});
}

/// Removes the output's value.
pub fn clear_output_value(&mut self) {
self.redact(|action| {
action.output.value = None;

Check warning on line 169 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L167-L169

Added lines #L167 - L169 were not covered by tests
});
}

/// Removes the seed randomness for the note being created.
pub fn clear_output_rseed(&mut self) {
self.redact(|action| {
action.output.rseed = None;

Check warning on line 176 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L174-L176

Added lines #L174 - L176 were not covered by tests
});
}

/// Removes the `ock` value used to encrypt `out_ciphertext`.
pub fn clear_output_ock(&mut self) {
self.redact(|action| {
action.output.ock = None;

Check warning on line 183 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L181-L183

Added lines #L181 - L183 were not covered by tests
});
}

/// Removes the ZIP 32 derivation path at which the spending key can be found for the
/// note being created.
pub fn clear_output_zip32_derivation(&mut self) {
self.redact(|action| {
action.output.zip32_derivation = None;

Check warning on line 191 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L189-L191

Added lines #L189 - L191 were not covered by tests
});
}

/// Removes the user-facing address to which the output is being sent, if any.
pub fn clear_output_user_address(&mut self) {
self.redact(|spend| {
spend.output.user_address = None;

Check warning on line 198 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L196-L198

Added lines #L196 - L198 were not covered by tests
});
}

/// Redacts the output-specific proprietary value at the given key.
pub fn redact_output_proprietary(&mut self, key: &str) {
self.redact(|action| {
action.output.proprietary.remove(key);

Check warning on line 205 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L203-L205

Added lines #L203 - L205 were not covered by tests
});
}

/// Removes all output-specific proprietary values.
pub fn clear_output_proprietary(&mut self) {
self.redact(|action| {
action.output.proprietary.clear();

Check warning on line 212 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L210-L212

Added lines #L210 - L212 were not covered by tests
});
}

/// Removes the value commitment randomness.
pub fn clear_rcv(&mut self) {
self.redact(|action| {
action.rcv = None;

Check warning on line 219 in pczt/src/roles/redactor/orchard.rs

View check run for this annotation

Codecov / codecov/patch

pczt/src/roles/redactor/orchard.rs#L217-L219

Added lines #L217 - L219 were not covered by tests
});
}
}
Loading
Loading