1#![no_std]
10#![deny(missing_docs)]
11#![deny(rustdoc::broken_intra_doc_links)]
12#![deny(clippy::pedantic)]
13#![allow(clippy::module_name_repetitions)]
14#![feature(cfg_eval)]
15#![allow(clippy::used_underscore_binding)]
16#![feature(const_fn_floating_point_arithmetic)]
17#![cfg_attr(not(target_family = "wasm"), deny(unused_crate_dependencies))]
18#![deny(unused_extern_crates)]
19
20extern crate alloc;
21
22pub mod abi;
23
24pub mod stake;
25pub mod transfer;
26
27mod error;
28pub use error::{Error, TxPreconditionError};
29
30mod dusk;
31pub use dusk::{dusk, from_dusk, Dusk, LUX};
32
33use blake2b_simd as _; pub use dusk_bls12_381::BlsScalar;
37pub use dusk_jubjub::{
38 JubJubAffine, JubJubExtended, JubJubScalar, GENERATOR_EXTENDED,
39 GENERATOR_NUMS_EXTENDED,
40};
41
42pub mod signatures {
44 pub mod bls {
46 pub use bls12_381_bls::{
47 Error, MultisigPublicKey, MultisigSignature, PublicKey, SecretKey,
48 Signature,
49 };
50 }
51
52 pub mod schnorr {
54 pub use jubjub_schnorr::{
55 PublicKey, SecretKey, Signature, SignatureDouble,
56 };
57 }
58}
59
60#[cfg(feature = "plonk")]
63pub mod plonk {
64 pub use dusk_plonk::prelude::{
65 Circuit, Compiler, Composer, Constraint, Error, Proof, Prover,
66 PublicParameters, Verifier, Witness, WitnessPoint,
67 };
68}
69
70#[cfg(feature = "groth16")]
72pub mod groth16 {
73 pub use ark_bn254 as bn254;
74 pub use ark_groth16::{
75 data_structures, generator, prepare_verifying_key, prover, r1cs_to_qap,
76 verifier, Groth16, PreparedVerifyingKey, Proof, ProvingKey,
77 VerifyingKey,
78 };
79 pub use ark_relations as relations;
80 pub use ark_serialize as serialize;
81}
82
83#[inline]
84const fn reserved(b: u8) -> abi::ContractId {
85 let mut bytes = [0u8; abi::CONTRACT_ID_BYTES];
86 bytes[0] = b;
87 abi::ContractId::from_bytes(bytes)
88}
89
90use alloc::string::String;
91use alloc::vec::Vec;
92
93use dusk_bytes::{DeserializableSlice, Error as BytesError};
94
95fn read_vec(buf: &mut &[u8]) -> Result<Vec<u8>, BytesError> {
101 let len = usize::try_from(u64::from_reader(buf)?)
102 .map_err(|_| BytesError::InvalidData)?;
103 if buf.len() < len {
104 return Err(BytesError::InvalidData);
105 }
106 let bytes = buf[..len].into();
107 *buf = &buf[len..];
108 Ok(bytes)
109}
110
111fn read_str(buf: &mut &[u8]) -> Result<String, BytesError> {
117 let len = usize::try_from(u64::from_reader(buf)?)
118 .map_err(|_| BytesError::InvalidData)?;
119 if buf.len() < len {
120 return Err(BytesError::InvalidData);
121 }
122 let str = String::from_utf8(buf[..len].into())
123 .map_err(|_| BytesError::InvalidData)?;
124 *buf = &buf[len..];
125 Ok(str)
126}
127
128fn read_arr<const N: usize>(buf: &mut &[u8]) -> Result<[u8; N], BytesError> {
134 if buf.len() < N {
135 return Err(BytesError::InvalidData);
136 }
137 let mut a = [0u8; N];
138 a.copy_from_slice(&buf[..N]);
139 *buf = &buf[N..];
140 Ok(a)
141}
142
143#[cfg(test)]
144mod tests {
145 use serde_json as _;
148}