lib.rs
 1  /* This file is part of DarkFi (https://dark.fi)
 2   *
 3   * Copyright (C) 2020-2025 Dyne.org foundation
 4   *
 5   * This program is free software: you can redistribute it and/or modify
 6   * it under the terms of the GNU Affero General Public License as
 7   * published by the Free Software Foundation, either version 3 of the
 8   * License, or (at your option) any later version.
 9   *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU Affero General Public License for more details.
14   *
15   * You should have received a copy of the GNU Affero General Public License
16   * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17   */
18  
19  use darkfi_sdk::{error::ContractError, pasta::pallas};
20  use darkfi_serial::{SerialDecodable, SerialEncodable};
21  
22  #[cfg(feature = "client")]
23  use darkfi_serial::async_trait;
24  
25  /// Functions available in the contract
26  #[repr(u8)]
27  pub enum ContractFunction {
28      Register = 0x00,
29      Deregister = 0x01,
30  }
31  
32  impl TryFrom<u8> for ContractFunction {
33      type Error = ContractError;
34  
35      fn try_from(b: u8) -> Result<Self, Self::Error> {
36          match b {
37              0x00 => Ok(Self::Register),
38              0x01 => Ok(Self::Deregister),
39              _ => Err(ContractError::InvalidFunction),
40          }
41      }
42  }
43  
44  /// Function parameters
45  #[derive(Debug, Clone, Copy, SerialEncodable, SerialDecodable)]
46  pub struct HelloParams {
47      /// X coordinate of the public key
48      pub x: pallas::Base,
49      /// Y coordinate of the public key
50      pub y: pallas::Base,
51  }
52  
53  #[cfg(not(feature = "no-entrypoint"))]
54  /// WASM entrypoint functions
55  pub mod entrypoint;
56  
57  /// This is a sled tree that will be created
58  pub const HELLO_CONTRACT_MEMBER_TREE: &str = "members";
59  
60  /// zkas circuit namespace
61  pub const HELLO_CONTRACT_ZKAS_SECRETCOMMIT_NS: &str = "SecretCommitment";