Skip to content

Commit ca8336f

Browse files
Added type conformances and create_credential_request is accessible now
1 parent d3cb9c0 commit ca8336f

File tree

4 files changed

+320
-92
lines changed

4 files changed

+320
-92
lines changed

uniffi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ serde = { version = "1.0", features = ["derive"] }
2929
serde_json = '1.0'
3030
swift-bridge = "0.1.51"
3131
ursa = { version = "0.3.7", default-features = false, features = ["cl_native", "serde"] }
32+
thiserror = "1.0.30"
3233

3334
[dev-dependencies.tokio]
3435
version = '1.9'

uniffi/src/anoncreds.udl

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
[Error]
2+
enum AnoncredsError {
3+
"ConversionError",
4+
"SomethingWentWrong",
5+
"CreateCrentialRequestError",
6+
};
7+
18
enum SignatureType {
29
"CL",
310
};
@@ -14,7 +21,7 @@ dictionary CredentialDefinitionID {
1421
string id;
1522
};
1623

17-
interface SecretLink {
24+
interface LinkSecret {
1825
constructor();
1926
string get_big_number();
2027
};
@@ -44,24 +51,38 @@ dictionary CredentialOffer {
4451
string? method_name;
4552
};
4653

54+
interface CredentialRequest {
55+
string get_blinded_credential_secrets_json();
56+
string get_blinded_credential_secrets_correctness_proof_json();
57+
Nonce get_nonce();
58+
string get_json();
59+
};
60+
61+
dictionary CredentialRequestMetadata {
62+
string link_secret_blinding_data;
63+
Nonce nonce;
64+
string link_secret_name;
65+
};
66+
4767
dictionary CreateCrendentialRequestResponse {
48-
string request;
49-
string metadata;
68+
CredentialRequest request;
69+
CredentialRequestMetadata metadata;
5070
};
5171

5272
interface Prover {
5373
constructor();
5474

55-
string create_credential_request(
75+
[Throws=AnoncredsError]
76+
CreateCrendentialRequestResponse create_credential_request(
5677
[ByRef] string entropy,
5778
[ByRef] string prover_did,
5879
[ByRef] CredentialDefinition cred_def,
59-
[ByRef] SecretLink link_secret,
80+
[ByRef] LinkSecret link_secret,
6081
[ByRef] string link_secret_id,
6182
[ByRef] CredentialOffer credential_offer
6283
);
6384

64-
SecretLink create_link_secret();
85+
LinkSecret create_link_secret();
6586
};
6687

6788
namespace anoncreds {};

uniffi/src/prover/mod.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use anoncreds_core::prover::*;
2+
use anoncreds_core::data_types::cred_request::{CredentialRequest as AnoncredsCredentialRequest, CredentialRequestMetadata as AnoncredsCredentialRequestMetadata};
23
use super::types::*;
34
use std::sync::Arc;
4-
5-
enum AnoncredsError {
6-
CreateCrentialRequestError
7-
}
5+
use std::convert::TryInto;
86

97
pub struct CreateCrendentialRequestResponse {
10-
pub request: String,
11-
pub metadata: String,
8+
pub request: Arc<CredentialRequest>,
9+
pub metadata: CredentialRequestMetadata,
1210
}
1311

1412
pub 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

Comments
 (0)