I am currently trying to create Verifiable Credentials from existing DIDs in my IOTA Sandbox based on the “examples” code from github (https://github.com/iotaledger/identity.rs/blob/main/examples/0_basic/5_create_vc.rs).
I managed to create the credentials but it seems impossible for me to sign them: I used the existing wallet and stronghold (for the issuer), existing DIDs (for issuer and holder) and also managed to resolve these DIDs to DID-Documents in my code. That all works, the problem is the part where I have to call create_credential_jwt(). I have no idea how I can access the fragment variable when using resolved DID-Documents. It works when creating new ones (like in the examples-link above) but how can I access this variable from resolved DIDs?
Here is my code:
<code> let client: Client = Client::builder()
.with_primary_node(api_endpoint, None)?
let mut resolver = Resolver::<IotaDocument>::new();
resolver.attach_iota_handler(client.clone());
// Parse and resolve the DIDs
let issuer_did = IotaDID::parse(did_string_issuer)?;
let holder_did = IotaDID::parse(did_string_holder)?;
let issuer_document = resolver.resolve(&issuer_did).await?;
let holder_document = resolver.resolve(&holder_did).await?;
println!("{:#}", issuer_document);
println!("{:#}", holder_document);
// Set up the issuer's secret manager and storage
let mut secret_manager_issuer: SecretManager = SecretManager::Stronghold(
StrongholdSecretManager::builder()
.password(Password::from(password.to_owned()))
// Create storage and load the key from the stronghold
let mut issuer_storage: MemStorage = MemStorage::new(JwkMemStore::new(), KeyIdMemstore::new());
// Create a credential subject indicating the degree earned by the Holder.
let subject: Subject = Subject::from_json_value(json!({
"id": holder_document.id().as_str(),
"name": "Master of Science in Computer Science",
// Build credential using subject above and issuer.
let credential: Credential = CredentialBuilder::default()
.id(Url::parse("https://example.edu/credentials/3732")?)
.issuer(Url::parse(issuer_document.id().as_str())?)
.type_("UniversityDegreeCredential")
//println!("Credential JSON > {:#}", credential);
// When creating the credential JWT, use the fragment_issuer variable:
let credential_jwt: Jwt = issuer_document
&fragment, // got this from the link <- wtf is this? How can I get it?
&JwsSignatureOptions::default(),
<code> let client: Client = Client::builder()
.with_primary_node(api_endpoint, None)?
.finish()
.await?;
// Set up resolver
let mut resolver = Resolver::<IotaDocument>::new();
resolver.attach_iota_handler(client.clone());
// Parse and resolve the DIDs
let issuer_did = IotaDID::parse(did_string_issuer)?;
let holder_did = IotaDID::parse(did_string_holder)?;
let issuer_document = resolver.resolve(&issuer_did).await?;
let holder_document = resolver.resolve(&holder_did).await?;
println!("{:#}", issuer_document);
println!("{:#}", holder_document);
// Set up the issuer's secret manager and storage
let mut secret_manager_issuer: SecretManager = SecretManager::Stronghold(
StrongholdSecretManager::builder()
.password(Password::from(password.to_owned()))
.build(stronghold_path)?
);
// Create storage and load the key from the stronghold
let mut issuer_storage: MemStorage = MemStorage::new(JwkMemStore::new(), KeyIdMemstore::new());
// Create a credential subject indicating the degree earned by the Holder.
let subject: Subject = Subject::from_json_value(json!({
"id": holder_document.id().as_str(),
"name": "Holder, BSc",
"degree": {
"type": "MastersDegree",
"name": "Master of Science in Computer Science",
},
"GPA": "4.0",
}))?;
// Build credential using subject above and issuer.
let credential: Credential = CredentialBuilder::default()
.id(Url::parse("https://example.edu/credentials/3732")?)
.issuer(Url::parse(issuer_document.id().as_str())?)
.type_("UniversityDegreeCredential")
.subject(subject)
.build()?;
//println!("Credential JSON > {:#}", credential);
// When creating the credential JWT, use the fragment_issuer variable:
let credential_jwt: Jwt = issuer_document
.create_credential_jwt(
&credential,
&issuer_storage,
&fragment, // got this from the link <- wtf is this? How can I get it?
&JwsSignatureOptions::default(),
None,
)
.await?;
</code>
let client: Client = Client::builder()
.with_primary_node(api_endpoint, None)?
.finish()
.await?;
// Set up resolver
let mut resolver = Resolver::<IotaDocument>::new();
resolver.attach_iota_handler(client.clone());
// Parse and resolve the DIDs
let issuer_did = IotaDID::parse(did_string_issuer)?;
let holder_did = IotaDID::parse(did_string_holder)?;
let issuer_document = resolver.resolve(&issuer_did).await?;
let holder_document = resolver.resolve(&holder_did).await?;
println!("{:#}", issuer_document);
println!("{:#}", holder_document);
// Set up the issuer's secret manager and storage
let mut secret_manager_issuer: SecretManager = SecretManager::Stronghold(
StrongholdSecretManager::builder()
.password(Password::from(password.to_owned()))
.build(stronghold_path)?
);
// Create storage and load the key from the stronghold
let mut issuer_storage: MemStorage = MemStorage::new(JwkMemStore::new(), KeyIdMemstore::new());
// Create a credential subject indicating the degree earned by the Holder.
let subject: Subject = Subject::from_json_value(json!({
"id": holder_document.id().as_str(),
"name": "Holder, BSc",
"degree": {
"type": "MastersDegree",
"name": "Master of Science in Computer Science",
},
"GPA": "4.0",
}))?;
// Build credential using subject above and issuer.
let credential: Credential = CredentialBuilder::default()
.id(Url::parse("https://example.edu/credentials/3732")?)
.issuer(Url::parse(issuer_document.id().as_str())?)
.type_("UniversityDegreeCredential")
.subject(subject)
.build()?;
//println!("Credential JSON > {:#}", credential);
// When creating the credential JWT, use the fragment_issuer variable:
let credential_jwt: Jwt = issuer_document
.create_credential_jwt(
&credential,
&issuer_storage,
&fragment, // got this from the link <- wtf is this? How can I get it?
&JwsSignatureOptions::default(),
None,
)
.await?;
And here is the part on where they get the fragment-variable from in the examples, when creating new DIDs (not in my code like that, because I resolved existing DID-Documents):
<code> let (_, issuer_document, fragment): (Address, IotaDocument, String) =
create_did(&client, &mut secret_manager_issuer, &issuer_storage).await?;
<code> let (_, issuer_document, fragment): (Address, IotaDocument, String) =
create_did(&client, &mut secret_manager_issuer, &issuer_storage).await?;
</code>
let (_, issuer_document, fragment): (Address, IotaDocument, String) =
create_did(&client, &mut secret_manager_issuer, &issuer_storage).await?;
Anyone know enough about Rust and/or the IOTA-SDK to help me get this fragment variable from resolved DID-Documents please?
Thank you in advance.