diff --git a/commit_verify/src/lib.rs b/commit_verify/src/lib.rs index 6e9d0e2c..9b509cb3 100644 --- a/commit_verify/src/lib.rs +++ b/commit_verify/src/lib.rs @@ -84,10 +84,102 @@ pub const LIB_NAME_COMMIT_VERIFY: &str = "CommitVerify"; pub trait CommitmentProtocol {} /// Protocol defining commits created by using externally created hash value -/// *optionally pretagged). +/// *optionally pre-tagged*. pub struct UntaggedProtocol; impl CommitmentProtocol for UntaggedProtocol {} +/// Reserved bytes. +#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)] +#[display("reserved")] +#[derive(StrictType, StrictEncode)] +#[strict_type(lib = LIB_NAME_COMMIT_VERIFY)] +pub struct ReservedBytes([u8; LEN]); + +impl Default for ReservedBytes { + fn default() -> Self { Self([VAL; LEN]) } +} + +impl From<[u8; LEN]> for ReservedBytes { + fn from(value: [u8; LEN]) -> Self { + assert_eq!(value, [VAL; LEN]); + Self(value) + } +} + +mod _reserved { + use strict_encoding::{DecodeError, ReadTuple, StrictDecode, TypedRead}; + + use crate::{CommitEncode, CommitEngine, ReservedBytes, StrictHash}; + + impl CommitEncode for ReservedBytes { + type CommitmentId = StrictHash; + + fn commit_encode(&self, e: &mut CommitEngine) { e.commit_to_serialized(self) } + } + + impl StrictDecode for ReservedBytes { + fn strict_decode(reader: &mut impl TypedRead) -> Result { + let reserved = reader.read_tuple(|r| r.read_field().map(Self))?; + if reserved != ReservedBytes::::default() { + Err(DecodeError::DataIntegrityError(format!( + "unsupported reserved byte value indicating a future RGB version. Please \ + update your software, or, if the problem persists, contact your vendor \ + providing the following version information: {reserved}" + ))) + } else { + Ok(reserved) + } + } + } + + #[cfg(feature = "serde")] + mod _serde { + use std::fmt; + + use serde_crate::de::Visitor; + use serde_crate::{de, Deserialize, Deserializer, Serialize, Serializer}; + + use super::*; + + impl Serialize for ReservedBytes { + fn serialize(&self, serializer: S) -> Result + where S: Serializer { + // Doing nothing + serializer.serialize_unit() + } + } + + impl<'de, const LEN: usize, const VAL: u8> Deserialize<'de> for ReservedBytes { + fn deserialize(deserializer: D) -> Result + where D: Deserializer<'de> { + #[derive(Default)] + pub struct UntaggedUnitVisitor; + + impl<'de> Visitor<'de> for UntaggedUnitVisitor { + type Value = (); + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + write!(formatter, "reserved unit") + } + + fn visit_none(self) -> Result<(), E> + where E: de::Error { + Ok(()) + } + + fn visit_unit(self) -> Result<(), E> + where E: de::Error { + Ok(()) + } + } + + deserializer.deserialize_unit(UntaggedUnitVisitor)?; + Ok(default!()) + } + } + } +} + /// Helpers for writing test functions working with commit schemes #[cfg(test)] pub mod test_helpers { diff --git a/commit_verify/src/stl.rs b/commit_verify/src/stl.rs index 1240f76b..57c6596e 100644 --- a/commit_verify/src/stl.rs +++ b/commit_verify/src/stl.rs @@ -21,15 +21,18 @@ use strict_types::{CompileError, LibBuilder, TypeLib}; -use crate::{mpc, MerkleHash, MerkleNode, StrictHash, LIB_NAME_COMMIT_VERIFY}; +use crate::{mpc, MerkleHash, MerkleNode, ReservedBytes, StrictHash, LIB_NAME_COMMIT_VERIFY}; pub const LIB_ID_COMMIT_VERIFY: &str = - "urn:ubideco:stl:7qvjR4HCwJKF3mxE5GqsAaADces5JDRwb8ajAse9mkz3#exhibit-karate-ritual"; + "urn:ubideco:stl:7EpM1uymEteG4g4xmF5ntKYX1wXXpbQj5iLiDreH4jWa#protein-donald-cool"; fn _commit_verify_stl() -> Result { LibBuilder::new(libname!(LIB_NAME_COMMIT_VERIFY), tiny_bset! { strict_types::stl::std_stl().to_dependency() }) + .transpile::>() + .transpile::>() + .transpile::>() .transpile::() .transpile::() .transpile::() diff --git a/stl/CommitVerify@0.1.0.sta b/stl/CommitVerify@0.1.0.sta index 1255495f..79adf775 100644 --- a/stl/CommitVerify@0.1.0.sta +++ b/stl/CommitVerify@0.1.0.sta @@ -1,11 +1,11 @@ -----BEGIN STRICT TYPE LIB----- -Id: urn:ubideco:stl:7qvjR4HCwJKF3mxE5GqsAaADces5JDRwb8ajAse9mkz3#exhibit-karate-ritual +Id: urn:ubideco:stl:7EpM1uymEteG4g4xmF5ntKYX1wXXpbQj5iLiDreH4jWa#protein-donald-cool Name: CommitVerify Dependency: DzTvt9gGhPUKD8Dkkjk9PDBhkJ4gtWxXWQjxnmUYLNrs#voyage-kimono-disco -Checksum-SHA256: ab9c647839dade059c136e1259383094050afe96493376d9debca2dc05173a4a +Checksum-SHA256: 33bbc0d7f6f0068636ff89a975b4ca52e6ccb9811b22e0f7aecdb69e5023fb4c 3`1{iZE18?WpZg|c>%!$%tl@;WNu_lcw-g2$nLVb<*lb*ENIx0;35YAw}=B%bYuY -oQ*>kj0A^Tl*p6J$36SYb7g#;qpQBTpwL(~+!(f@;t~vt?k^)sV3;+s4Z*6U9bZu +oQ*>kj0A^Tl*p6J$36SYb7g#;qpQBTpwL(~+!(f@;t~vt?k^)sV4*&{7Z*6U9bZu pBbOiwb2LJ#-AOHkRWnpFn0uTvlZfId*X>?^|00sgGaB^>SZ)0z40Wg(*<{e=)S- S-YV@1=_p5>Oab-~jC R3C`SFec^=zG+gvC|O;Wo~qGZ*X}41_B3VZgg^QaCra#2m^3$a{vGY3r%HmYiwmg @@ -24,13 +24,14 @@ u0Wg(*<{e=)S-S-YmzVsZkZk>V@1=_p5>Oab- ~jCR3C`SFec^=zG+gvC{wm0000000960{{R30000ARVQ>Hn000C41p)yum44Q3WPbltNdpi 4*91)SI!>0000000000|Ns90000002Tf&jb75y?1pxpD002NB01ZxWWMx8fVQyn+ -X>Ml&0|a(&X=DHfb7^j8Y-IrkVsc?_V`u^jP;zf{Z)0z4Nn`~900#g7Kp+4LQ*?4 -^V{}Mib7%zt00#g7Kp+4JRB~lyPH$vo1OfmJV{dL_WnpY(WKM5nWdH^O1!QG#bZ7 -#>1k6TWEM#tEO?YD!yU6acy5+5>Uo2?YlHei-0Jn%{Sa8^mT+s=T=}Z?`J=~w8Q= -GLzSfImTncuED0}GM_Xkl|`0X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