mirror of https://github.com/zcash/halo2.git
Add canonical byte conversions for value commitments.
This commit is contained in:
parent
fc0f55d82b
commit
75573d331a
|
@ -7,7 +7,7 @@ use crate::{
|
|||
note::{ExtractedNoteCommitment, Nullifier, TransmittedNoteCiphertext},
|
||||
primitives::redpallas::{self, Binding, SpendAuth},
|
||||
tree::Anchor,
|
||||
value::{ValueCommitment},
|
||||
value::ValueCommitment,
|
||||
};
|
||||
|
||||
/// An action applied to the global ledger.
|
||||
|
|
13
src/value.rs
13
src/value.rs
|
@ -14,7 +14,7 @@
|
|||
//! [`Action`]: crate::bundle::Action
|
||||
//! [`Bundle`]: crate::bundle::Bundle
|
||||
|
||||
use std::convert::{TryInto, TryFrom};
|
||||
use std::convert::{TryFrom, TryInto};
|
||||
use std::fmt::{self, Debug};
|
||||
use std::iter::Sum;
|
||||
use std::ops::{Add, Sub};
|
||||
|
@ -27,6 +27,7 @@ use pasta_curves::{
|
|||
pallas,
|
||||
};
|
||||
use rand::RngCore;
|
||||
use subtle::CtOption;
|
||||
|
||||
use crate::primitives::redpallas::{self, Binding};
|
||||
|
||||
|
@ -214,6 +215,16 @@ impl ValueCommitment {
|
|||
// TODO: impl From<pallas::Point> for redpallas::VerificationKey.
|
||||
self.0.to_bytes().try_into().unwrap()
|
||||
}
|
||||
|
||||
/// Deserialize a value commitment from its byte representation
|
||||
pub fn from_bytes(bytes: &[u8; 32]) -> CtOption<ValueCommitment> {
|
||||
pallas::Point::from_bytes(bytes).map(ValueCommitment)
|
||||
}
|
||||
|
||||
/// Serialize this value commitment to its canonical byte representation.
|
||||
pub fn to_bytes(&self) -> [u8; 32] {
|
||||
self.0.to_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Reference in New Issue