rgbstd/containers/
certs.rs

1// RGB standard library for working with smart contracts on Bitcoin & Lightning
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Written in 2019-2023 by
6//     Dr Maxim Orlovsky <orlovsky@lnp-bp.org>
7//
8// Copyright (C) 2019-2023 LNP/BP Standards Association. All rights reserved.
9//
10// Licensed under the Apache License, Version 2.0 (the "License");
11// you may not use this file except in compliance with the License.
12// You may obtain a copy of the License at
13//
14//     http://www.apache.org/licenses/LICENSE-2.0
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS,
18// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19// See the License for the specific language governing permissions and
20// limitations under the License.
21
22use std::collections::{btree_set, BTreeSet};
23
24use amplify::confinement::{Confined, TinyAscii, TinyBlob, TinyString};
25use rgb::{ContractId, SchemaId};
26
27use crate::interface::{IfaceId, ImplId, SupplId};
28use crate::LIB_NAME_RGB_STD;
29
30#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
31#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
32#[strict_type(lib = LIB_NAME_RGB_STD, tags = order, dumb = ContentId::Schema(strict_dumb!()))]
33#[cfg_attr(
34    feature = "serde",
35    derive(Serialize, Deserialize),
36    serde(crate = "serde_crate", rename_all = "camelCase")
37)]
38pub enum ContentId {
39    Schema(SchemaId),
40    Genesis(ContractId),
41    Iface(IfaceId),
42    IfaceImpl(ImplId),
43    Suppl(SupplId),
44}
45
46#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Display)]
47#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
48#[strict_type(lib = LIB_NAME_RGB_STD)]
49#[cfg_attr(
50    feature = "serde",
51    derive(Serialize, Deserialize),
52    serde(crate = "serde_crate", rename_all = "camelCase")
53)]
54#[display("{name} <{email}>; using={suite}")]
55#[non_exhaustive]
56pub struct Identity {
57    pub name: TinyString,
58    pub email: TinyAscii,
59    pub suite: IdSuite,
60    pub pk: TinyBlob,
61}
62
63#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Display)]
64#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
65#[strict_type(lib = LIB_NAME_RGB_STD, tags = repr, into_u8, try_from_u8)]
66#[cfg_attr(
67    feature = "serde",
68    derive(Serialize, Deserialize),
69    serde(crate = "serde_crate", rename_all = "camelCase")
70)]
71#[non_exhaustive]
72#[repr(u8)]
73pub enum IdSuite {
74    #[strict_type(dumb)]
75    #[display("OpenPGP")]
76    Pgp,
77    #[display("OpenSSH")]
78    Ssh,
79    #[display("SSI")]
80    Ssi,
81}
82
83#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
84#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
85#[strict_type(lib = LIB_NAME_RGB_STD)]
86#[cfg_attr(
87    feature = "serde",
88    derive(Serialize, Deserialize),
89    serde(crate = "serde_crate", rename_all = "camelCase")
90)]
91pub struct Cert {
92    pub signer: Identity,
93    pub signature: TinyBlob,
94}
95
96#[derive(Wrapper, WrapperMut, Clone, PartialEq, Eq, Hash, Debug, From)]
97#[wrapper(Deref)]
98#[wrapper_mut(DerefMut)]
99#[derive(StrictDumb, StrictType, StrictEncode, StrictDecode)]
100#[strict_type(lib = LIB_NAME_RGB_STD, dumb = Self(confined_bset!(strict_dumb!())))]
101#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "serde_crate"))]
102pub struct ContentSigs(Confined<BTreeSet<Cert>, 1, 10>);
103
104impl IntoIterator for ContentSigs {
105    type Item = Cert;
106    type IntoIter = btree_set::IntoIter<Cert>;
107
108    fn into_iter(self) -> Self::IntoIter { self.0.into_iter() }
109}