Skip to main content

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
28use dusk_jubjub::{
29    GENERATOR_EXTENDED, GENERATOR_NUMS_EXTENDED, JubJubAffine, JubJubScalar,
30};
31pub use encryption::aes;
32pub use error::Error;
33pub use keys::hash;
34pub use keys::public::PublicKey;
35pub use keys::secret::SecretKey;
36pub use keys::view::ViewKey;
37pub use note::{Note, NoteType, Sender, VALUE_ENC_SIZE as NOTE_VAL_ENC_SIZE};
38pub use stealth_address::StealthAddress;
39#[cfg(feature = "alloc")]
40/// Transaction Skeleton used by the phoenix transaction model
41pub use transaction::TxSkeleton;
42
43/// Use the pedersen commitment scheme to compute a transparent value
44/// commitment.
45pub fn transparent_value_commitment(value: u64) -> JubJubAffine {
46    JubJubAffine::from(GENERATOR_EXTENDED * JubJubScalar::from(value))
47}
48
49/// Use the pedersen commitment scheme to compute a value commitment using a
50/// blinding-factor.
51pub fn value_commitment(
52    value: u64,
53    blinding_factor: JubJubScalar,
54) -> JubJubAffine {
55    JubJubAffine::from(
56        (GENERATOR_EXTENDED * JubJubScalar::from(value))
57            + (GENERATOR_NUMS_EXTENDED * blinding_factor),
58    )
59}