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
33pub use dusk_bls12_381::BlsScalar;
35pub use dusk_jubjub::{
36 JubJubAffine, JubJubExtended, JubJubScalar, GENERATOR_EXTENDED,
37 GENERATOR_NUMS_EXTENDED,
38};
39
40pub mod signatures {
42 pub mod bls {
44 pub use bls12_381_bls::{
45 Error, MultisigPublicKey, MultisigSignature, PublicKey, SecretKey,
46 Signature,
47 };
48 }
49
50 pub mod schnorr {
52 pub use jubjub_schnorr::{
53 PublicKey, SecretKey, Signature, SignatureDouble,
54 };
55 }
56}
57
58#[cfg(feature = "plonk")]
61pub mod plonk {
62 pub use dusk_plonk::prelude::{
63 Circuit, Compiler, Composer, Constraint, Error, Proof, Prover,
64 PublicParameters, Verifier, Witness, WitnessPoint,
65 };
66}
67
68#[cfg(feature = "groth16")]
70pub mod groth16 {
71 pub use ark_bn254 as bn254;
72 pub use ark_groth16::{
73 data_structures, generator, prepare_verifying_key, prover, r1cs_to_qap,
74 verifier, Groth16, PreparedVerifyingKey, Proof, ProvingKey,
75 VerifyingKey,
76 };
77 pub use ark_relations as relations;
78 pub use ark_serialize as serialize;
79}
80
81#[inline]
82const fn reserved(b: u8) -> abi::ContractId {
83 let mut bytes = [0u8; abi::CONTRACT_ID_BYTES];
84 bytes[0] = b;
85 abi::ContractId::from_bytes(bytes)
86}
87
88use alloc::string::String;
89use alloc::vec::Vec;
90
91use dusk_bytes::{DeserializableSlice, Error as BytesError};
92
93fn read_vec(buf: &mut &[u8]) -> Result<Vec<u8>, BytesError> {
99 let len = usize::try_from(u64::from_reader(buf)?)
100 .map_err(|_| BytesError::InvalidData)?;
101 if buf.len() < len {
102 return Err(BytesError::InvalidData);
103 }
104 let bytes = buf[..len].into();
105 *buf = &buf[len..];
106 Ok(bytes)
107}
108
109fn read_str(buf: &mut &[u8]) -> Result<String, BytesError> {
115 let len = usize::try_from(u64::from_reader(buf)?)
116 .map_err(|_| BytesError::InvalidData)?;
117 if buf.len() < len {
118 return Err(BytesError::InvalidData);
119 }
120 let str = String::from_utf8(buf[..len].into())
121 .map_err(|_| BytesError::InvalidData)?;
122 *buf = &buf[len..];
123 Ok(str)
124}
125
126fn read_arr<const N: usize>(buf: &mut &[u8]) -> Result<[u8; N], BytesError> {
132 if buf.len() < N {
133 return Err(BytesError::InvalidData);
134 }
135 let mut a = [0u8; N];
136 a.copy_from_slice(&buf[..N]);
137 *buf = &buf[N..];
138 Ok(a)
139}
140
141#[cfg(test)]
142mod tests {
143 use serde_json as _;
146}