rgbcore/operation/
seal.rs1use core::fmt::Debug;
24use std::hash::Hash;
25
26pub use bp::seals::txout::blind::{ChainBlindSeal, ParseError, SingleBlindSeal};
27use bp::seals::txout::ExplicitSeal;
28pub use bp::seals::txout::TxoSeal;
29pub use bp::seals::SecretSeal;
30use bp::Txid;
31use commit_verify::Conceal;
32use strict_encoding::{StrictDecode, StrictDumb, StrictEncode};
33
34pub type GenesisSeal = SingleBlindSeal;
35pub type GraphSeal = ChainBlindSeal;
36
37pub type OutputSeal = ExplicitSeal<Txid>;
38
39pub trait ExposedSeal:
40 Debug
41 + StrictDumb
42 + StrictEncode
43 + StrictDecode
44 + Eq
45 + Ord
46 + Copy
47 + Hash
48 + TxoSeal
49 + Conceal<Concealed = SecretSeal>
50{
51 #[inline]
52 fn to_output_seal(self) -> Option<OutputSeal> {
53 let outpoint = self.outpoint()?;
54 Some(ExplicitSeal::new(outpoint))
55 }
56
57 fn to_output_seal_or_default(self, witness_id: Txid) -> OutputSeal {
58 self.to_output_seal()
59 .unwrap_or(ExplicitSeal::new(self.outpoint_or(witness_id)))
60 }
61}
62
63impl ExposedSeal for GraphSeal {}
64
65impl ExposedSeal for GenesisSeal {}
66
67#[cfg(test)]
68mod test {
69 use amplify::hex::FromHex;
70 use bp::seals::txout::{BlindSeal, TxPtr};
71 use bp::Vout;
72
73 use super::*;
74
75 #[test]
76 fn secret_seal_is_sha256d() {
77 let reveal = BlindSeal {
78 blinding: 54683213134637,
79 txid: TxPtr::Txid(
80 Txid::from_hex("646ca5c1062619e2a2d60771c9dfd820551fb773e4dc8c4ed67965a8d1fae839")
81 .unwrap(),
82 ),
83 vout: Vout::from(2),
84 };
85 let secret = reveal.to_secret_seal();
86 assert_eq!(
87 secret.to_string(),
88 "utxob:nBRVm39A-ioJydHE-ug2d90m-aZyfPI0-MCc0ZNM-oMXMs2O-opKQ7"
89 );
90 assert_eq!(reveal.to_secret_seal(), reveal.conceal())
91 }
92}