@@ -217,6 +217,33 @@ pub struct CredentialDefinition {
217217 pub issuer_id : IssuerID ,
218218}
219219
220+ impl CredentialDefinition {
221+ pub fn new ( json_string : String ) -> Result < Self , AnoncredsError > {
222+ let core_def: AnoncredsCredentialDefinition = serde_json:: from_str ( & json_string) . map_err ( |_| AnoncredsError :: ConversionError ) ?;
223+ return CredentialDefinition :: try_from ( core_def)
224+ }
225+
226+ pub fn get_schema_id ( & self ) -> SchemaID {
227+ self . schema_id . clone ( )
228+ }
229+
230+ pub fn get_signature_type ( & self ) -> SignatureType {
231+ self . signature_type . clone ( )
232+ }
233+
234+ pub fn get_tag ( & self ) -> String {
235+ self . tag . clone ( )
236+ }
237+
238+ pub fn get_value ( & self ) -> CredentialDefinitionData {
239+ self . value . clone ( )
240+ }
241+
242+ pub fn get_issuer_id ( & self ) -> IssuerID {
243+ self . issuer_id . clone ( )
244+ }
245+ }
246+
220247impl TryInto < AnoncredsCredentialDefinition > for CredentialDefinition {
221248 type Error = AnoncredsError ;
222249
@@ -279,6 +306,33 @@ pub struct CredentialOffer {
279306 pub method_name : Option < String > ,
280307}
281308
309+ impl CredentialOffer {
310+ pub fn new ( jsonString : String ) -> Result < Self , AnoncredsError > {
311+ let core_def: AnoncredsCredentialOffer = serde_json:: from_str ( & jsonString) . map_err ( |_| AnoncredsError :: ConversionError ) ?;
312+ return CredentialOffer :: try_from ( core_def)
313+ }
314+
315+ pub fn get_schema_id ( & self ) -> SchemaID {
316+ self . schema_id . clone ( )
317+ }
318+
319+ pub fn get_cred_def_id ( & self ) -> CredentialDefinitionID {
320+ self . cred_def_id . clone ( )
321+ }
322+
323+ pub fn get_key_correctness_proof ( & self ) -> String {
324+ self . key_correctness_proof . clone ( )
325+ }
326+
327+ pub fn get_nonce ( & self ) -> Arc < Nonce > {
328+ self . nonce . clone ( )
329+ }
330+
331+ pub fn get_method_name ( & self ) -> Option < String > {
332+ self . method_name . clone ( )
333+ }
334+ }
335+
282336impl TryFrom < AnoncredsCredentialOffer > for CredentialOffer {
283337 type Error = AnoncredsError ;
284338
@@ -320,26 +374,6 @@ impl TryFrom<&CredentialOffer> for AnoncredsCredentialOffer {
320374 }
321375}
322376
323- // impl CredentialOffer {
324- // pub fn to_core(&self) -> Result<AnoncredsCredentialOffer, AnoncredsError> {
325- // let schema_id_core = self.schema_id.clone().into();
326- // let cred_def_id_core = self.cred_def_id.clone().into();
327- // let key_correctness_proof_core: ursa::cl::CredentialKeyCorrectnessProof = serde_json::from_str(&self.key_correctness_proof)
328- // .map_err(|_| AnoncredsError::ConversionError)?; // Handle serde_json::Error here
329- // let nonce_unwrap = (*self.nonce).clone();
330- // let nonce_core = nonce_unwrap.anoncreds_nonce;
331- // let method_name_core = self.method_name.clone();
332-
333- // Ok(AnoncredsCredentialOffer {
334- // schema_id: schema_id_core,
335- // cred_def_id: cred_def_id_core,
336- // key_correctness_proof: key_correctness_proof_core,
337- // nonce: nonce_core,
338- // method_name: method_name_core,
339- // })
340- // }
341- // }
342-
343377pub struct CredentialRequest {
344378 pub anoncreds_request : AnoncredsCredentialRequest
345379}
0 commit comments