11use anoncreds_core:: prover:: * ;
2+ use anoncreds_core:: data_types:: cred_request:: { CredentialRequest as AnoncredsCredentialRequest , CredentialRequestMetadata as AnoncredsCredentialRequestMetadata } ;
23use super :: types:: * ;
34use std:: sync:: Arc ;
4-
5- enum AnoncredsError {
6- CreateCrentialRequestError
7- }
5+ use std:: convert:: TryInto ;
86
97pub struct CreateCrendentialRequestResponse {
10- pub request : String ,
11- pub metadata : String ,
8+ pub request : Arc < CredentialRequest > ,
9+ pub metadata : CredentialRequestMetadata ,
1210}
1311
1412pub struct Prover {
@@ -22,37 +20,36 @@ impl Prover {
2220 }
2321 }
2422
25- // pub fn create_credential_request(&self, schema_id: &SchemaID) -> String {
26- // return self.str.clone();
27- // }
28-
2923 pub fn create_credential_request (
3024 & self ,
3125 entropy : & str ,
3226 prover_did : & str ,
3327 cred_def : & CredentialDefinition ,
34- link_secret : & SecretLink ,
28+ link_secret : & LinkSecret ,
3529 link_secret_id : & str ,
3630 credential_offer : & CredentialOffer ,
37- ) -> String {
38- let cred_def_core = cred_def. to_core ( ) . unwrap ( ) ;
39- let link_secret_core = link_secret. to_core ( ) ;
40- let cred_offer_core = credential_offer. to_core ( ) . unwrap ( ) ;
31+ ) -> Result < CreateCrendentialRequestResponse , AnoncredsError > {
32+ let cred_def_core = cred_def. try_into ( ) ? ;
33+ let link_secret_core = link_secret. try_into ( ) ? ;
34+ let cred_offer_core = credential_offer. try_into ( ) ? ;
4135
42- let result = anoncreds_core:: prover:: create_credential_request (
36+ let ( request , metadata ) = anoncreds_core:: prover:: create_credential_request (
4337 Some ( entropy) ,
4438 Some ( prover_did) ,
4539 & cred_def_core,
4640 & link_secret_core,
4741 link_secret_id,
4842 & cred_offer_core
49- ) ;
43+ ) . map_err ( |_| AnoncredsError :: CreateCrentialRequestError ) ? ;
5044
51- return String :: from ( "Hello world!" )
45+ return Ok ( CreateCrendentialRequestResponse {
46+ request : Arc :: new ( CredentialRequest { anoncreds_request : request } ) ,
47+ metadata : CredentialRequestMetadata :: from ( metadata)
48+ } )
5249 }
5350
54- pub fn create_link_secret ( & self ) -> Arc < SecretLink > {
55- let secret = SecretLink :: new ( ) ;
51+ pub fn create_link_secret ( & self ) -> Arc < LinkSecret > {
52+ let secret = LinkSecret :: new ( ) ;
5653 Arc :: new ( secret)
5754 }
5855}
0 commit comments