use serde::{Deserialize, Serialize};
pub use moonproof_ledger::coin_structure::contract::ContractAddress;
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct PrivateStateId(pub String);
impl PrivateStateId {
#[must_use]
pub fn new(s: impl Into<String>) -> Self {
Self(s.into())
}
#[inline]
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for PrivateStateId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl From<&str> for PrivateStateId {
fn from(s: &str) -> Self {
PrivateStateId(s.to_owned())
}
}
impl From<String> for PrivateStateId {
fn from(s: String) -> Self {
PrivateStateId(s)
}
}
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct BlockHash(pub String);
impl BlockHash {
#[must_use]
pub fn new(s: impl Into<String>) -> Self {
Self(s.into())
}
#[inline]
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
}
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct TransactionId(pub String);
impl TransactionId {
#[must_use]
pub fn new(s: impl Into<String>) -> Self {
Self(s.into())
}
#[inline]
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for TransactionId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct TransactionHash(pub String);
impl TransactionHash {
#[must_use]
pub fn new(s: impl Into<String>) -> Self {
Self(s.into())
}
#[inline]
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
}
#[derive(Debug, Default, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct CircuitId(pub String);
impl CircuitId {
#[must_use]
pub fn new(s: impl Into<String>) -> Self {
Self(s.into())
}
#[inline]
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for CircuitId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl From<&str> for CircuitId {
fn from(s: &str) -> Self {
Self(s.to_owned())
}
}
impl From<&CircuitId> for CircuitId {
fn from(c: &CircuitId) -> Self {
c.clone()
}
}
impl From<String> for CircuitId {
fn from(s: String) -> Self {
Self(s)
}
}
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct CoinPublicKey(pub [u8; 32]);
impl CoinPublicKey {
#[must_use]
pub fn to_hex(&self) -> String {
hex::encode(self.0)
}
}
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct EncPublicKey(pub [u8; 32]);
impl EncPublicKey {
#[must_use]
pub fn to_hex(&self) -> String {
hex::encode(self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Zkir(pub Vec<u8>);
impl Zkir {
#[must_use]
pub fn new(bytes: impl Into<Vec<u8>>) -> Self {
Self(bytes.into())
}
#[inline]
#[must_use]
pub fn as_bytes(&self) -> &[u8] {
&self.0
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProverKey(pub Vec<u8>);
impl ProverKey {
#[must_use]
pub fn new(bytes: impl Into<Vec<u8>>) -> Self {
Self(bytes.into())
}
#[inline]
#[must_use]
pub fn as_bytes(&self) -> &[u8] {
&self.0
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VerifierKey(pub Vec<u8>);
impl VerifierKey {
#[must_use]
pub fn new(bytes: impl Into<Vec<u8>>) -> Self {
Self(bytes.into())
}
#[inline]
#[must_use]
pub fn as_bytes(&self) -> &[u8] {
&self.0
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ZkConfig {
pub circuit_id: CircuitId,
pub prover_key: ProverKey,
pub verifier_key: VerifierKey,
pub zkir: Zkir,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn private_state_id_as_str_roundtrips() {
let id = PrivateStateId::new("hello");
assert_eq!(id.as_str(), "hello");
assert_eq!(format!("{id}"), "hello");
}
#[test]
fn circuit_id_from_str_and_display() {
let id: CircuitId = "increment".into();
assert_eq!(id.as_str(), "increment");
assert_eq!(format!("{id}"), "increment");
}
#[test]
fn zk_artifact_byte_accessors() {
let z = Zkir::new(vec![1u8, 2, 3]);
assert_eq!(z.as_bytes(), &[1, 2, 3]);
let pk = ProverKey::new(vec![9u8, 9, 9]);
assert_eq!(pk.as_bytes(), &[9, 9, 9]);
let vk = VerifierKey::new(vec![0xff, 0xee]);
assert_eq!(vk.as_bytes(), &[0xff, 0xee]);
}
#[test]
fn coin_pubkey_hex_is_lowercase_64_chars() {
let pk = CoinPublicKey([0xabu8; 32]);
let hex = pk.to_hex();
assert_eq!(hex.len(), 64);
assert_eq!(hex, "ab".repeat(32));
}
}