cml_chain_wasm/crypto/
mod.rs1pub use cml_crypto_wasm::{
5 AnchorDocHash, AuxiliaryDataHash, BlockBodyHash, BlockHeaderHash, DatumHash, Ed25519KeyHash,
6 Ed25519Signature, GenesisDelegateHash, GenesisHash, KESVkey, NonceHash, PoolMetadataHash,
7 ScriptDataHash, ScriptHash, TransactionHash, VRFKeyHash, VRFVkey,
8};
9
10pub mod hash;
11pub mod utils;
12
13use wasm_bindgen::prelude::{wasm_bindgen, JsError};
14
15use cml_core_wasm::{impl_wasm_cbor_json_api, impl_wasm_conversions};
16
17use crate::byron::AddrAttributes;
18
19pub type Vkey = cml_crypto_wasm::PublicKey;
20
21#[derive(Clone, Debug)]
22#[wasm_bindgen]
23pub struct BootstrapWitness(cml_chain::crypto::BootstrapWitness);
24
25impl_wasm_cbor_json_api!(BootstrapWitness);
26
27impl_wasm_conversions!(cml_chain::crypto::BootstrapWitness, BootstrapWitness);
28
29#[wasm_bindgen]
30impl BootstrapWitness {
31 pub fn public_key(&self) -> Vkey {
32 self.0.public_key.clone().into()
33 }
34
35 pub fn signature(&self) -> Ed25519Signature {
36 self.0.signature.clone().into()
37 }
38
39 pub fn chain_code(&self) -> Vec<u8> {
40 self.0.chain_code.clone()
41 }
42
43 pub fn attributes(&self) -> AddrAttributes {
44 self.0.attributes.clone().into()
45 }
46
47 pub fn new(
48 public_key: &Vkey,
49 signature: &Ed25519Signature,
50 chain_code: Vec<u8>,
51 attributes: &AddrAttributes,
52 ) -> Result<BootstrapWitness, JsError> {
53 cml_chain::crypto::BootstrapWitness::new(
54 public_key.clone().into(),
55 signature.clone().into(),
56 chain_code,
57 attributes.clone().into(),
58 )
59 .map(Into::into)
60 .map_err(Into::into)
61 }
62}
63
64#[derive(Clone, Debug)]
65#[wasm_bindgen]
66pub struct KESSignature(cml_chain::crypto::KESSignature);
67
68impl_wasm_cbor_json_api!(KESSignature);
69
70impl_wasm_conversions!(cml_chain::crypto::KESSignature, KESSignature);
71
72#[wasm_bindgen]
73impl KESSignature {
74 pub fn get(&self) -> Vec<u8> {
75 self.0.get().clone()
76 }
77}
78
79#[derive(Clone, Debug)]
80#[wasm_bindgen]
81pub struct Nonce(cml_chain::crypto::Nonce);
82
83impl_wasm_cbor_json_api!(Nonce);
84
85impl_wasm_conversions!(cml_chain::crypto::Nonce, Nonce);
86
87#[wasm_bindgen]
88impl Nonce {
89 pub fn new_identity() -> Self {
90 Self(cml_chain::crypto::Nonce::new_identity())
91 }
92
93 pub fn new_hash(hash: &NonceHash) -> Self {
94 Self(cml_chain::crypto::Nonce::new_hash(hash.clone().into()))
95 }
96
97 pub fn kind(&self) -> NonceKind {
98 match &self.0 {
99 cml_chain::crypto::Nonce::Identity { .. } => NonceKind::Identity,
100 cml_chain::crypto::Nonce::Hash { .. } => NonceKind::Hash,
101 }
102 }
103
104 pub fn as_hash(&self) -> Option<NonceHash> {
105 match &self.0 {
106 cml_chain::crypto::Nonce::Hash { hash, .. } => Some((*hash).into()),
107 _ => None,
108 }
109 }
110}
111
112#[wasm_bindgen]
113pub enum NonceKind {
114 Identity,
115 Hash,
116}
117
118#[derive(Clone, Debug)]
119#[wasm_bindgen]
120pub struct VRFCert(cml_chain::crypto::VRFCert);
121
122impl_wasm_cbor_json_api!(VRFCert);
123
124impl_wasm_conversions!(cml_chain::crypto::VRFCert, VRFCert);
125
126#[wasm_bindgen]
127impl VRFCert {
128 pub fn output(&self) -> Vec<u8> {
129 self.0.output.clone()
130 }
131
132 pub fn proof(&self) -> Vec<u8> {
133 self.0.proof.clone()
134 }
135
136 pub fn new(output: Vec<u8>, proof: Vec<u8>) -> Result<VRFCert, JsError> {
137 cml_chain::crypto::VRFCert::new(output, proof)
138 .map(Into::into)
139 .map_err(Into::into)
140 }
141}
142
143#[derive(Clone, Debug)]
144#[wasm_bindgen]
145pub struct Vkeywitness(cml_chain::crypto::Vkeywitness);
146
147impl_wasm_cbor_json_api!(Vkeywitness);
148
149impl_wasm_conversions!(cml_chain::crypto::Vkeywitness, Vkeywitness);
150
151#[wasm_bindgen]
152impl Vkeywitness {
153 pub fn vkey(&self) -> Vkey {
154 self.0.vkey.clone().into()
155 }
156
157 pub fn ed25519_signature(&self) -> Ed25519Signature {
158 self.0.ed25519_signature.clone().into()
159 }
160
161 pub fn new(vkey: &Vkey, ed25519_signature: &Ed25519Signature) -> Self {
162 Self(cml_chain::crypto::Vkeywitness::new(
163 vkey.clone().into(),
164 ed25519_signature.clone().into(),
165 ))
166 }
167}