pub struct DTGCredential { /* private fields */ }Expand description
Defined DTG Credentials
Implementations§
Source§impl DTGCredential
impl DTGCredential
Sourcepub fn new_vmc(
issuer: String,
subject: String,
valid_from: DateTime<Utc>,
valid_until: Option<DateTime<Utc>>,
personhood: bool,
) -> Self
pub fn new_vmc( issuer: String, subject: String, valid_from: DateTime<Utc>, valid_until: Option<DateTime<Utc>>, personhood: bool, ) -> Self
Creates a new Verified Memebrship Credential (VMC) issuer: The issuer DID of the credential subject: The DID of the subject of this credential valid_from: The datetime from which this credential is valid valid_until: Optional: The datetime this credential is valid until personhood: Whether this VMC can be used as a form of Personhood Credential - Adds PersonhoodCredential to the type array if true
Sourcepub fn new_vrc(
issuer: String,
subject: String,
valid_from: DateTime<Utc>,
valid_until: Option<DateTime<Utc>>,
) -> Self
pub fn new_vrc( issuer: String, subject: String, valid_from: DateTime<Utc>, valid_until: Option<DateTime<Utc>>, ) -> Self
Creates a new Verified Relationship Credential (VRC) issuer: The issuer DID of the credential subject: The DID of the subject of this credential valid_from: The datetime from which this credential is valid valid_until: Optional: The datetime this credential is valid until
Sourcepub fn new_vic(
issuer: String,
subject: String,
valid_from: DateTime<Utc>,
valid_until: Option<DateTime<Utc>>,
) -> Self
pub fn new_vic( issuer: String, subject: String, valid_from: DateTime<Utc>, valid_until: Option<DateTime<Utc>>, ) -> Self
Creates a new Verified Invitation Credential (VIC) issuer: The issuer DID of the credential subject: The DID of the subject of this credential valid_from: The datetime from which this credential is valid valid_until: Optional: The datetime this credential is valid until
Sourcepub fn new_vpc(
issuer: String,
subject: String,
valid_from: DateTime<Utc>,
valid_until: Option<DateTime<Utc>>,
) -> Self
pub fn new_vpc( issuer: String, subject: String, valid_from: DateTime<Utc>, valid_until: Option<DateTime<Utc>>, ) -> Self
Creates a new Verified Persona Credential (VPC) issuer: The issuer DID of the credential subject: The DID of the subject of this credential valid_from: The datetime from which this credential is valid valid_until: Optional: The datetime this credential is valid until
Sourcepub fn new_vec(
issuer: String,
subject: String,
valid_from: DateTime<Utc>,
valid_until: Option<DateTime<Utc>>,
endorsement: Value,
) -> Self
pub fn new_vec( issuer: String, subject: String, valid_from: DateTime<Utc>, valid_until: Option<DateTime<Utc>>, endorsement: Value, ) -> Self
Creates a new Verified Endorsement Credential (VEC) issuer: The issuer DID of the credential subject: The DID of the subject of this credential valid_from: The datetime from which this credential is valid valid_until: Optional: The datetime this credential is valid until endorsement: The endorsement details for this credential
Sourcepub fn new_vwc(
issuer: String,
subject: String,
valid_from: DateTime<Utc>,
valid_until: Option<DateTime<Utc>>,
task_context: String,
digest: Option<String>,
witness_context: Option<WitnessContext>,
) -> Self
pub fn new_vwc( issuer: String, subject: String, valid_from: DateTime<Utc>, valid_until: Option<DateTime<Utc>>, task_context: String, digest: Option<String>, witness_context: Option<WitnessContext>, ) -> Self
Creates a new Verified Witness Credential (VWC)
issuer: The issuer DID of the credential - an M-DID, or the DID of a VTA acting
according to VTC policy
subject: The DID of the observed party. For a witnessed bi-directional exchange this
MUST be the issuer of the VRC that this VWC attests (the VRC referenced by
digest), so that the two VWCs of an exchange are unambiguously bound to
their respective directions. The witness should issue one VWC per direction.
valid_from: The datetime from which this credential is valid
valid_until: Optional: The datetime this credential is valid until
task_context: Required threadId of the trust task exchange the witnessing occurred in
digest: Optional Witness cryptographic hash of the witnessed VRC (prevents misuse).
Produce this with DTGCredential::digest_multibase on the witnessed VRC.
witness_context: Optional Semantic context for the witness
Sourcepub fn new_rcard(
issuer: String,
subject: String,
valid_from: DateTime<Utc>,
valid_until: Option<DateTime<Utc>>,
card: Value,
) -> Self
👎Deprecated since 0.2.0: The r-card is a verifiable data structure (VDS), not a DTGCredential subtype. It was removed from the DTG Core Credentials specification in Working Draft 01 and will be defined by the planned DTG Verifiable Data Structures specification. This constructor will be removed in a future release.
pub fn new_rcard( issuer: String, subject: String, valid_from: DateTime<Utc>, valid_until: Option<DateTime<Utc>>, card: Value, ) -> Self
The r-card is a verifiable data structure (VDS), not a DTGCredential subtype. It was removed from the DTG Core Credentials specification in Working Draft 01 and will be defined by the planned DTG Verifiable Data Structures specification. This constructor will be removed in a future release.
Creates a new Verified RCard Credential (VWC) issuer: The issuer DID of the credential subject: The DID of the subject of this credential valid_from: The datetime from which this credential is valid valid_until: Optional: The datetime this credential is valid until card: JSON Value representing a Jcard (RFC 7095) format
Sourcepub fn with_id(self, id: impl Into<String>) -> Self
pub fn with_id(self, id: impl Into<String>) -> Self
Sets this credential’s own identifier, consuming and returning it so it chains onto
any of the new_* constructors above.
id MUST be a single URL per the W3C VC Data Model; urn:uuid:<uuid> is the usual
choice for a credential with no dereferenceable home. This crate does not validate it.
let vmc = DTGCredential::new_vmc(
"did:example:member".to_string(),
"did:example:community".to_string(),
Utc::now(),
None,
false,
)
.with_id("urn:uuid:2a4e1d90-6e0c-4d3f-9a4a-6d0a8f7c1b52");
assert_eq!(vmc.id(), Some("urn:uuid:2a4e1d90-6e0c-4d3f-9a4a-6d0a8f7c1b52"));§Set it before signing
A Data Integrity proof covers the credential minus its proof, so id is part of what
is signed. Chain this onto the constructor, before DTGCredential::sign — adding an id
to an already-signed credential leaves a document whose proof no longer verifies.
Sourcepub fn set_id(&mut self, id: impl Into<String>)
pub fn set_id(&mut self, id: impl Into<String>)
Sets this credential’s own identifier in place.
The non-consuming form of DTGCredential::with_id; the same “before signing” caveat applies.
Source§impl DTGCredential
impl DTGCredential
Sourcepub fn credential(&self) -> &DTGCommon
pub fn credential(&self) -> &DTGCommon
get the raw credential
Sourcepub fn credential_mut(&mut self) -> &mut DTGCommon
pub fn credential_mut(&mut self) -> &mut DTGCommon
Get the raw credential as mutable
Sourcepub fn type_(&self) -> DTGCredentialType
pub fn type_(&self) -> DTGCredentialType
get the credential type
Sourcepub fn id(&self) -> Option<&str>
pub fn id(&self) -> Option<&str>
This credential’s own identifier, if it has one.
None for a credential built by one of the new_* constructors and never given one
with DTGCredential::with_id. See DTGCommon::id for why a counterparty may require
it.
Sourcepub fn valid_from(&self) -> DateTime<Utc>
pub fn valid_from(&self) -> DateTime<Utc>
Returns the valid_from timestamp
Sourcepub fn valid_until(&self) -> Option<DateTime<Utc>>
pub fn valid_until(&self) -> Option<DateTime<Utc>>
Returns the valid until timestamp
Sourcepub fn task_context(&self) -> Option<&str>
pub fn task_context(&self) -> Option<&str>
The threadId of the trust task exchange this credential was issued in, if set
This is always Some for DTGCredentialType::Witness credentials, where the spec
makes taskContext REQUIRED.
Sourcepub fn digest_multibase(&self) -> Result<String, DTGCredentialError>
pub fn digest_multibase(&self) -> Result<String, DTGCredentialError>
Computes the digest of this credential, for use as the digest property of a
Witness Credential (VWC) attesting it.
The digest is the SHA-256 hash of this credential canonicalized with the JSON
Canonicalization Scheme (JCS, RFC 8785),
wrapped as a multihash and encoded as a base58btc multibase string (z...), matching
the W3C digestMultibase convention.
§⚠️ Known spec divergence
This encoding is not what DTG Core Credentials Working Draft 01 specifies. WD-01
requires sha256: followed by a lowercase hex digest; this returns a multibase
multihash. The underlying hash is identical — only the encoding differs — but the
literal digest strings will not match, so VWCs built with this value will not
interoperate with spec-conformant implementations, and DTGCredential::verify_digest
will reject conformant VWCs from elsewhere.
This is unresolved and should be raised with the DTGWG. Do not rely on this function if you must interoperate with conformant implementations today. See README.md.
The digest covers the credential exactly as it stands, including its proof if it has
been signed. A witness should therefore digest the VRC in the form it was witnessed in.
Sourcepub fn verify_digest(
&self,
witnessed: &DTGCredential,
) -> Result<bool, DTGCredentialError>
pub fn verify_digest( &self, witnessed: &DTGCredential, ) -> Result<bool, DTGCredentialError>
Checks that this credential’s digest matches the credential it claims to witness.
Returns Ok(false) if the digests do not match, or if this credential carries no
digest (it is OPTIONAL), in which case there is nothing to rely on.
§⚠️ Known spec divergence
This compares against DTGCredential::digest_multibase, whose encoding differs from
DTG Core Credentials Working Draft 01. A conformant VWC carrying a sha256:<hex>
digest will be rejected by this function even when the underlying credential is
the one it genuinely witnesses. See DTGCredential::digest_multibase and README.md.
Sourcepub fn proof_value(&self) -> Option<&str>
pub fn proof_value(&self) -> Option<&str>
Returns the proof value if signed else None
Sourcepub async fn sign(
&mut self,
signing_secret: &Secret,
create_time: Option<DateTime<Utc>>,
) -> Result<DataIntegrityProof, DTGCredentialError>
pub async fn sign( &mut self, signing_secret: &Secret, create_time: Option<DateTime<Utc>>, ) -> Result<DataIntegrityProof, DTGCredentialError>
Sign the credential using W3C Data Integrity Proof with JCS EdDSA 2022 signing_secret: The secret key to use to sign the credential create_time: Optional creation time for the proof, defaults to now if None
Sourcepub fn verify_proof_with_public_key(
&self,
public_key_bytes: &[u8],
) -> Result<(), DTGCredentialError>
pub fn verify_proof_with_public_key( &self, public_key_bytes: &[u8], ) -> Result<(), DTGCredentialError>
Verify the credential if you already know the public key bytes otherwise use the affinidi_tdk:verify_data() method public_key_bytes: The public key bytes to use to verify the credential
Sourcepub fn get_w3c_vc_version(&self) -> W3CVCVersion
pub fn get_w3c_vc_version(&self) -> W3CVCVersion
Is this credential a W3C VC Version 1.1 or 2.0 credential?
Sourcepub fn is_personhood_credential(&self) -> bool
pub fn is_personhood_credential(&self) -> bool
returns true if this credential a personhood credential (PHC)
Trait Implementations§
Source§impl Clone for DTGCredential
impl Clone for DTGCredential
Source§fn clone(&self) -> DTGCredential
fn clone(&self) -> DTGCredential
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more