Accept an Amount<NonNegative> for the value arg of a ValueCommitment constructor
This commit is contained in:
parent
e024e43896
commit
be7ea200c8
|
@ -316,13 +316,12 @@ impl ValueCommitment {
|
|||
/// Generate a new _ValueCommitment_.
|
||||
///
|
||||
/// https://zips.z.cash/protocol/protocol.pdf#concretehomomorphiccommit
|
||||
// TODO: accept an Amount instead?
|
||||
#[allow(non_snake_case)]
|
||||
pub fn new<T>(csprng: &mut T, value_bytes: [u8; 32]) -> Self
|
||||
pub fn new<T>(csprng: &mut T, value: Amount<NonNegative>) -> Self
|
||||
where
|
||||
T: RngCore + CryptoRng,
|
||||
{
|
||||
let v = jubjub::Fr::from_bytes(&value_bytes).unwrap();
|
||||
let v = jubjub::Fr::from(value);
|
||||
let rcv = generate_trapdoor(csprng);
|
||||
|
||||
let V = find_group_hash(*b"Zcash_cv", b"v");
|
||||
|
|
|
@ -132,6 +132,16 @@ impl From<Amount<NonNegative>> for u64 {
|
|||
}
|
||||
}
|
||||
|
||||
impl<C> From<Amount<C>> for jubjub::Fr {
|
||||
fn from(a: Amount<C>) -> jubjub::Fr {
|
||||
if a.0 < 0 {
|
||||
jubjub::Fr::from(a.0.abs() as u64).neg()
|
||||
} else {
|
||||
jubjub::Fr::from(a.0 as u64)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> TryFrom<i64> for Amount<C>
|
||||
where
|
||||
C: AmountConstraint,
|
||||
|
|
Loading…
Reference in New Issue