ultrasonic/
util.rs

1// UltraSONIC: transactional execution layer with capability-based memory access for zk-AluVM
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Designed in 2019-2025 by Dr Maxim Orlovsky <orlovsky@ubideco.org>
6// Written in 2024-2025 by Dr Maxim Orlovsky <orlovsky@ubideco.org>
7//
8// Copyright (C) 2019-2024 LNP/BP Standards Association, Switzerland.
9// Copyright (C) 2024-2025 Laboratories for Ubiquitous Deterministic Computing (UBIDECO),
10//                         Institute for Distributed and Cognitive Systems (InDCS), Switzerland.
11// Copyright (C) 2019-2025 Dr Maxim Orlovsky.
12// All rights under the above copyrights are reserved.
13//
14// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
15// in compliance with the License. You may obtain a copy of the License at
16//
17//        http://www.apache.org/licenses/LICENSE-2.0
18//
19// Unless required by applicable law or agreed to in writing, software distributed under the License
20// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
21// or implied. See the License for the specific language governing permissions and limitations under
22// the License.
23
24use commit_verify::StrictHash;
25use strict_encoding::stl::AsciiPrintable;
26use strict_encoding::RString;
27
28use crate::LIB_NAME_ULTRASONIC;
29
30/// An ASCII printable string up to 4096 chars representing identity of a developer.
31///
32/// We deliberately do not define the internal structure of the identity such that it can be updated
33/// without changes to the consensus level.
34///
35/// Contract or schema validity doesn't assume any checks on the identity; these checks must be
36/// performed at the application level.
37#[derive(Wrapper, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, From, Display)]
38#[wrapper(Deref, FromStr)]
39#[display(inner)]
40#[derive(StrictType, StrictEncode, StrictDecode)]
41#[strict_type(lib = LIB_NAME_ULTRASONIC)]
42#[derive(CommitEncode)]
43#[commit_encode(strategy = strict, id = StrictHash)]
44#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(transparent))]
45pub struct Identity(RString<AsciiPrintable, AsciiPrintable, 1, 4096>);
46
47impl Default for Identity {
48    fn default() -> Self { Self::from("ssi:anonymous") }
49}
50
51impl From<&'static str> for Identity {
52    fn from(s: &'static str) -> Self { Self(RString::from(s)) }
53}
54
55impl Identity {
56    pub fn is_empty(&self) -> bool { self.is_anonymous() }
57    pub fn is_anonymous(&self) -> bool { self == &default!() }
58}