1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Copyright (c) DUSK NETWORK. All rights reserved.

//! Phoenix's Core library types and behaviors

#![allow(non_snake_case)]
#![deny(missing_docs)]
#![no_std]

mod encryption;
mod error;
mod keys;
mod note;
mod stealth_address;

#[cfg(feature = "alloc")]
mod transaction;

/// The number of output notes in a transaction
pub const OUTPUT_NOTES: usize = 2;

pub use encryption::{aes, elgamal};
pub use error::Error;
pub use keys::hash;
pub use keys::public::PublicKey;
pub use keys::secret::SecretKey;
pub use keys::view::ViewKey;
pub use note::{
    encrypt_sender, Note, NoteType, VALUE_ENC_SIZE as NOTE_VAL_ENC_SIZE,
};
pub use stealth_address::StealthAddress;

#[cfg(feature = "alloc")]
/// Transaction Skeleton used by the phoenix transaction model
pub use transaction::TxSkeleton;

use dusk_jubjub::{
    JubJubAffine, JubJubScalar, GENERATOR_EXTENDED, GENERATOR_NUMS_EXTENDED,
};

/// Use the pedersen commitment scheme to compute a transparent value
/// commitment.
pub fn transparent_value_commitment(value: u64) -> JubJubAffine {
    JubJubAffine::from(GENERATOR_EXTENDED * JubJubScalar::from(value))
}

/// Use the pedersen commitment scheme to compute a value commitment using a
/// blinding-factor.
pub fn value_commitment(
    value: u64,
    blinding_factor: JubJubScalar,
) -> JubJubAffine {
    JubJubAffine::from(
        (GENERATOR_EXTENDED * JubJubScalar::from(value))
            + (GENERATOR_NUMS_EXTENDED * blinding_factor),
    )
}