whisky_pallas/wrapper/witness_set/
vkey_witness.rs

1use std::str::FromStr;
2
3use pallas::{
4    codec::utils::Bytes,
5    ledger::primitives::{conway::VKeyWitness as PallasVKeyWitness, Fragment},
6};
7
8#[derive(Debug, PartialEq, Eq, Clone)]
9pub struct VKeyWitness {
10    pub inner: PallasVKeyWitness,
11}
12
13impl VKeyWitness {
14    pub fn new(vkey: String, signature: String) -> Result<Self, String> {
15        let inner = PallasVKeyWitness {
16            vkey: Bytes::from_str(&vkey).map_err(|e| e.to_string())?,
17            signature: Bytes::from_str(&signature).map_err(|e| e.to_string())?,
18        };
19        Ok(Self { inner })
20    }
21
22    pub fn encode(&self) -> String {
23        hex::encode(
24            self.inner
25                .encode_fragment()
26                .expect("encoding failed at VKeyWitness"),
27        )
28    }
29
30    pub fn decode_bytes(bytes: &[u8]) -> Result<Self, String> {
31        let inner = PallasVKeyWitness::decode_fragment(&bytes)
32            .map_err(|e| format!("Fragment decode error: {}", e.to_string()))?;
33        Ok(Self { inner })
34    }
35}