File tree Expand file tree Collapse file tree 5 files changed +32
-4
lines changed Expand file tree Collapse file tree 5 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,11 @@ enum RegistryType {
3636
3737interface LinkSecret {
3838 constructor();
39+ [Throws=AnoncredsError, Name=new_from_json]
40+ constructor(string json_string);
3941 string get_big_number();
42+ [Throws=AnoncredsError]
43+ string get_json();
4044};
4145
4246interface Nonce {
@@ -75,6 +79,8 @@ interface CredentialDefinition {
7579 SignatureType get_signature_type();
7680 string get_tag();
7781 IssuerId get_issuer_id();
82+ [Throws=AnoncredsError]
83+ string get_json();
7884};
7985
8086interface CredentialOffer {
@@ -85,18 +91,22 @@ interface CredentialOffer {
8591 string get_key_correctness_proof();
8692 Nonce get_nonce();
8793 string? get_method_name();
94+ [Throws=AnoncredsError]
95+ string get_json();
8896};
8997
9098interface CredentialRequest {
9199 string get_blinded_credential_secrets_json();
92100 string get_blinded_credential_secrets_correctness_proof_json();
93101 Nonce get_nonce();
102+ [Throws=AnoncredsError]
94103 string get_json();
95104};
96105
97106interface CredentialKeyCorrectnessProof {
98107 [Throws=AnoncredsError]
99108 constructor(string json_string);
109+ [Throws=AnoncredsError]
100110 string get_json();
101111};
102112
Original file line number Diff line number Diff line change @@ -84,6 +84,10 @@ impl CredentialDefinition {
8484 pub fn get_issuer_id ( & self ) -> IssuerId {
8585 self . core . issuer_id . clone ( )
8686 }
87+
88+ pub fn get_json ( & self ) -> Result < String , AnoncredsError > {
89+ serde_json:: to_string ( & self . core ) . map_err ( |_| AnoncredsError :: ConversionError )
90+ }
8791}
8892
8993impl TryInto < AnoncredsCredentialDefinition > for CredentialDefinition {
@@ -191,8 +195,8 @@ impl CredentialKeyCorrectnessProof {
191195 return Ok ( CredentialKeyCorrectnessProof { core : core_def } )
192196 }
193197
194- pub fn get_json ( & self ) -> String {
195- serde_json:: to_string ( & self . core . value ) . unwrap ( )
198+ pub fn get_json ( & self ) -> Result < String , AnoncredsError > {
199+ serde_json:: to_string ( & self . core ) . map_err ( |_| AnoncredsError :: ConversionError )
196200 }
197201}
198202
Original file line number Diff line number Diff line change @@ -42,6 +42,10 @@ impl CredentialOffer {
4242 pub fn get_method_name ( & self ) -> Option < String > {
4343 self . core . method_name . clone ( )
4444 }
45+
46+ pub fn get_json ( & self ) -> Result < String , AnoncredsError > {
47+ serde_json:: to_string ( & self . core ) . map_err ( |_| AnoncredsError :: ConversionError )
48+ }
4549}
4650
4751impl Clone for CredentialOffer {
Original file line number Diff line number Diff line change @@ -24,8 +24,8 @@ impl CredentialRequest {
2424 return Arc :: new ( Nonce { anoncreds_nonce : self . core . nonce . try_clone ( ) . unwrap ( ) } )
2525 }
2626
27- pub fn get_json ( & self ) -> String {
28- serde_json:: to_string ( & self . core ) . unwrap ( )
27+ pub fn get_json ( & self ) -> Result < String , AnoncredsError > {
28+ serde_json:: to_string ( & self . core ) . map_err ( |_| AnoncredsError :: ConversionError )
2929 }
3030}
3131
Original file line number Diff line number Diff line change @@ -14,10 +14,20 @@ impl LinkSecret {
1414 LinkSecret { secret : secret }
1515 }
1616
17+ pub fn new_from_json ( json_string : String ) -> Result < Self , AnoncredsError > {
18+ let core_def = AnoncredsLinkSecret :: try_from ( json_string. as_str ( ) ) . map_err ( |_| AnoncredsError :: ConversionError ) ?;
19+ return Ok ( LinkSecret { secret : core_def } )
20+ }
21+
1722 pub fn get_big_number ( & self ) -> String {
1823 let clone = self . clone ( ) ;
1924 clone. into ( )
2025 }
26+
27+ pub fn get_json ( & self ) -> Result < String , AnoncredsError > {
28+ let clone = self . clone ( ) ;
29+ return Ok ( clone. into ( ) )
30+ }
2131}
2232
2333impl From < AnoncredsLinkSecret > for LinkSecret {
You can’t perform that action at this time.
0 commit comments