phoenix_core/
lib.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4//
5// Copyright (c) DUSK NETWORK. All rights reserved.
6
7//! Phoenix's Core library types and behaviors
8
9#![allow(non_snake_case)]
10#![deny(missing_docs)]
11#![no_std]
12
13mod encryption;
14mod error;
15mod keys;
16mod note;
17mod stealth_address;
18
19#[cfg(feature = "alloc")]
20mod transaction;
21
22#[cfg(feature = "serde")]
23mod serde_support;
24
25/// The number of output notes in a transaction
26pub const OUTPUT_NOTES: usize = 2;
27
28pub use encryption::aes;
29pub use error::Error;
30pub use keys::hash;
31pub use keys::public::PublicKey;
32pub use keys::secret::SecretKey;
33pub use keys::view::ViewKey;
34pub use note::{Note, NoteType, Sender, VALUE_ENC_SIZE as NOTE_VAL_ENC_SIZE};
35pub use stealth_address::StealthAddress;
36
37#[cfg(feature = "alloc")]
38/// Transaction Skeleton used by the phoenix transaction model
39pub use transaction::TxSkeleton;
40
41use dusk_jubjub::{
42    JubJubAffine, JubJubScalar, GENERATOR_EXTENDED, GENERATOR_NUMS_EXTENDED,
43};
44
45/// Use the pedersen commitment scheme to compute a transparent value
46/// commitment.
47pub fn transparent_value_commitment(value: u64) -> JubJubAffine {
48    JubJubAffine::from(GENERATOR_EXTENDED * JubJubScalar::from(value))
49}
50
51/// Use the pedersen commitment scheme to compute a value commitment using a
52/// blinding-factor.
53pub fn value_commitment(
54    value: u64,
55    blinding_factor: JubJubScalar,
56) -> JubJubAffine {
57    JubJubAffine::from(
58        (GENERATOR_EXTENDED * JubJubScalar::from(value))
59            + (GENERATOR_NUMS_EXTENDED * blinding_factor),
60    )
61}