Skip to content

Commit

Permalink
change parameter name from subject_did to issuer_did in self issued c…
Browse files Browse the repository at this point in the history
…redential helper
  • Loading branch information
S3bb1 committed Nov 27, 2023
1 parent 285c703 commit 034f615
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 32 deletions.
15 changes: 5 additions & 10 deletions src/api/vade_evan_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ impl VadeEvan {
/// * `schema_did` - schema to create the credential
/// * `credential_subject_str` - JSON string of CredentialSubject structure
/// * `exp_date` - expiration date, string, e.g. "1722-12-03T14:23:42.120Z" (or `None` if no expiration date is used)
/// * `subject_did` - subject did for self issued credential
/// * `issuer_did` - issuer did for self issued credential
///
/// # Returns
/// * credential as JSON serialized [`BbsCredential`](https://docs.rs/vade_evan_bbs/*/vade_evan_bbs/struct.BbsCredential.html)
Expand All @@ -1127,7 +1127,7 @@ impl VadeEvan {
/// "email":"value@x.com"
/// }
/// }"#;
/// const SUBJECT_DID: &str = "did:evan:EiAee4ixDnSP0eWyp0YFV7Wt9yrZ3w841FNuv9NSLFSCVA";
/// const ISSUER_DID: &str = "did:evan:EiAee4ixDnSP0eWyp0YFV7Wt9yrZ3w841FNuv9NSLFSCVA";
///
/// async fn example() -> Result<()> {
/// let mut vade_evan = VadeEvan::new(VadeEvanConfig { target: DEFAULT_TARGET, signer: DEFAULT_SIGNER })?;
Expand All @@ -1136,7 +1136,7 @@ impl VadeEvan {
/// SCHEMA_DID,
/// CREDENTIAL_SUBJECT_STR,
/// None,
/// SUBJECT_DID,
/// ISSUER_DID,
/// )
/// .await?;
///
Expand All @@ -1153,16 +1153,11 @@ impl VadeEvan {
schema_did: &str,
credential_subject_str: &str,
exp_date: Option<&str>,
subject_did: &str,
issuer_did: &str,
) -> Result<String, VadeEvanError> {
let mut credential = Credential::new(self)?;
credential
.create_self_issued_credential(
schema_did,
credential_subject_str,
exp_date,
subject_did,
)
.create_self_issued_credential(schema_did, credential_subject_str, exp_date, issuer_did)
.await
.map_err(|err| err.into())
}
Expand Down
24 changes: 8 additions & 16 deletions src/helpers/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,16 @@ use super::shared::{check_for_optional_empty_params, convert_to_nquads, is_did,
use bbs::{
prelude::{DeterministicPublicKey, PublicKey},
signature::Signature,
HashElem,
SignatureMessage,
HashElem, SignatureMessage,
};
use flate2::read::GzDecoder;
use serde::de::DeserializeOwned;
use serde_json::{value::Value, Map};
use thiserror::Error;
use vade_evan_bbs::{
BbsCredential,
CredentialDraftOptions,
CredentialSchema,
CredentialStatus,
CredentialSubject,
LdProofVcDetailOptionsCredentialStatusType,
OfferCredentialPayload,
RevocationListCredential,
RevocationListProofKeys,
RevokeCredentialPayload,
BbsCredential, CredentialDraftOptions, CredentialSchema, CredentialStatus, CredentialSubject,
LdProofVcDetailOptionsCredentialStatusType, OfferCredentialPayload, RevocationListCredential,
RevocationListProofKeys, RevokeCredentialPayload,
};

#[derive(Error, Debug)]
Expand Down Expand Up @@ -391,7 +383,7 @@ impl<'a> Credential<'a> {
/// * `schema_did` - schema to create the credential
/// * `credential_subject_str` - JSON string of CredentialSubject structure
/// * `exp_date` - expiration date, string, e.g. "1722-12-03T14:23:42.120Z" (or `None` if no expiration date is used)
/// * `subject_did` - subject did for self issued credential
/// * `issuer_did` - issuer did for self issued credential
///
/// # Returns
/// * credential as JSON serialized [`UnsignedBbsCredential`](https://docs.rs/vade_evan_bbs/*/vade_evan_bbs/struct.UnsignedBbsCredential.html)
Expand All @@ -400,10 +392,10 @@ impl<'a> Credential<'a> {
schema_did: &str,
credential_subject_str: &str,
exp_date: Option<&str>,
subject_did: &str,
issuer_did: &str,
) -> Result<String, CredentialError> {
fail_if_not_a_did(schema_did, "schema_did")?;
fail_if_not_a_did(subject_did, "subject_did")?;
fail_if_not_a_did(issuer_did, "issuer_did")?;
let exp_date = check_for_optional_empty_params(exp_date);
let credential_subject: CredentialSubject = serde_json::from_str(credential_subject_str)?;

Expand All @@ -417,7 +409,7 @@ impl<'a> Credential<'a> {

let schema: CredentialSchema = self.get_did_document(schema_did).await?;
let draft_credential = schema.to_draft_credential(CredentialDraftOptions {
issuer_did: subject_did.to_owned(),
issuer_did: issuer_did.to_owned(),
id: None,
issuance_date: None,
valid_until,
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ async fn main() -> Result<()> {
get_argument_value(sub_m, "schema_did", None),
get_argument_value(sub_m, "credential_subject", None),
get_optional_argument_value(sub_m, "exp_date"),
get_argument_value(sub_m, "subject_did", None),
get_argument_value(sub_m, "issuer_did", None),
)
.await?
}
Expand Down Expand Up @@ -462,7 +462,7 @@ fn add_subcommand_helper<'a>(app: App<'a, 'a>) -> Result<App<'a, 'a>> {
.arg(get_clap_argument("schema_did")?)
.arg(get_clap_argument("credential_subject")?)
.arg(get_clap_argument("exp_date")?)
.arg(get_clap_argument("subject_did")?)
.arg(get_clap_argument("issuer_did")?)
);
} else {}
}
Expand Down
8 changes: 4 additions & 4 deletions src/wasm_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ struct HelperCreateSelfIssuedCredentialPayload {
pub schema_did: String,
pub credential_subject_str: String,
pub exp_date: Option<String>,
pub subject_did: String,
pub issuer_did: String,
}

#[derive(Serialize, Deserialize)]
Expand Down Expand Up @@ -433,15 +433,15 @@ cfg_if::cfg_if! {
schema_did: String,
credential_subject_str: String,
exp_date: Option<String>,
subject_did: String,
issuer_did: String,
) -> Result<String, JsValue> {
let mut vade_evan = get_vade_evan(None).map_err(jsify_generic_error)?;
Ok(vade_evan
.helper_create_self_issued_credential(
&schema_did,
&credential_subject_str,
exp_date.as_deref(),
&subject_did,
&issuer_did,
).await
.map_err(jsify_vade_evan_error)?)
}
Expand Down Expand Up @@ -801,7 +801,7 @@ pub async fn execute_vade(
payload.schema_did,
payload.credential_subject_str,
payload.exp_date,
payload.subject_did,
payload.issuer_did,
)
.await
}
Expand Down

0 comments on commit 034f615

Please sign in to comment.