Skip to content

Commit addbfb3

Browse files
Added build methods from json string for CredentialDefinition and CredentialOffer
1 parent ca8336f commit addbfb3

File tree

3 files changed

+74
-34
lines changed

3 files changed

+74
-34
lines changed

uniffi/src/anoncreds.udl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,24 @@ dictionary CredentialDefinitionData {
3535
string? revocation;
3636
};
3737

38-
dictionary CredentialDefinition {
39-
SchemaID schema_id;
40-
SignatureType signature_type;
41-
string tag;
42-
CredentialDefinitionData value;
43-
IssuerID issuer_id;
38+
interface CredentialDefinition {
39+
[Throws=AnoncredsError]
40+
constructor(string json_string);
41+
SchemaID get_schema_id();
42+
SignatureType get_signature_type();
43+
string get_tag();
44+
CredentialDefinitionData get_value();
45+
IssuerID get_issuer_id();
4446
};
4547

46-
dictionary CredentialOffer {
47-
SchemaID schema_id;
48-
CredentialDefinitionID cred_def_id;
49-
string key_correctness_proof;
50-
Nonce nonce;
51-
string? method_name;
48+
interface CredentialOffer {
49+
[Throws=AnoncredsError]
50+
constructor(string json_string);
51+
SchemaID get_schema_id();
52+
CredentialDefinitionID get_cred_def_id();
53+
string get_key_correctness_proof();
54+
Nonce get_nonce();
55+
string? get_method_name();
5256
};
5357

5458
interface CredentialRequest {

uniffi/src/prover/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ impl Prover {
2424
&self,
2525
entropy: &str,
2626
prover_did: &str,
27-
cred_def: &CredentialDefinition,
27+
cred_def: &Arc<CredentialDefinition>,
2828
link_secret: &LinkSecret,
2929
link_secret_id: &str,
3030
credential_offer: &CredentialOffer,
3131
) -> Result<CreateCrendentialRequestResponse, AnoncredsError> {
32-
let cred_def_core = cred_def.try_into()?;
32+
let cred_def_clone = Arc::clone(&cred_def);
33+
let cred_def_inner = cred_def_clone.as_ref();
34+
let cred_def_core = cred_def_inner.clone().try_into()?;
3335
let link_secret_core = link_secret.try_into()?;
3436
let cred_offer_core = credential_offer.try_into()?;
3537

uniffi/src/types/mod.rs

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
220247
impl 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+
282336
impl 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-
343377
pub struct CredentialRequest {
344378
pub anoncreds_request: AnoncredsCredentialRequest
345379
}

0 commit comments

Comments
 (0)