Class: VerifiableCredential

VerifiableCredential(id)

Representation of a Verifiable Credential.

Constructor

new VerifiableCredential(id)

Create a new Verifiable Credential instance.
Parameters:
Name Type Description
id string id of the credential
Source:

Methods

(static) fromJSON(json) → {VerifiableCredential}

Creates a new VerifiableCredential instance from a JSON object
Parameters:
Name Type Description
json object VC JSON
Source:
Returns:
Type
VerifiableCredential

(static) verifyID(id)

Fail if the given verifiable credential id isn't a valid URI.
Parameters:
Name Type Description
id *
Source:

addContext(context) → {VerifiableCredential}

Add a context to this Credential's context array. Duplicates are omitted.
Parameters:
Name Type Description
context string | object Context to add to the credential context array
Source:
Returns:
Type
VerifiableCredential

addSubject(subject) → {VerifiableCredential}

Add a subject to this Credential. Duplicates are omitted.
Parameters:
Name Type Description
subject object Subject of the credential
Source:
Returns:
Type
VerifiableCredential

addType(type) → {VerifiableCredential}

Add a type to this Credential's type array. Duplicates are omitted.
Parameters:
Name Type Description
type string Type to add to the credential type array
Source:
Returns:
Type
VerifiableCredential

setContext(context) → {VerifiableCredential}

Sets the context to the given value, overrding all others
Parameters:
Name Type Description
context string | object Context to assign
Source:
Returns:
Type
VerifiableCredential

setExpirationDate(expirationDate) → {VerifiableCredential}

Set a expiration date for this Credential
Parameters:
Name Type Description
expirationDate object expirationDate of the credential
Source:
Returns:
Type
VerifiableCredential

setFromJSON(json) → {VerifiableCredential}

Sets this credential's properties based on a JSON object
Parameters:
Name Type Description
json object VC JSON
Source:
Returns:
Type
VerifiableCredential

setId(id) → {VerifiableCredential}

Sets the credential's ID
Parameters:
Name Type Description
id string Signed credential's ID
Source:
Returns:
Type
VerifiableCredential

setIssuanceDate(issuanceDate) → {VerifiableCredential}

Set a issuance date for this Credential
Parameters:
Name Type Description
issuanceDate string issuanceDate of the credential
Source:
Returns:
Type
VerifiableCredential

setIssuer(issuer) → {VerifiableCredential}

Sets the credential's issuer DID
Parameters:
Name Type Description
issuer string the issuer's did
Source:
Returns:
Type
VerifiableCredential

setProof(proof) → {VerifiableCredential}

Sets the credential's proof
Parameters:
Name Type Description
proof object Signed credential proof
Source:
Returns:
Type
VerifiableCredential

setSchema(id, type)

Sets the `credentialSchema` field of the credential with the given id and type as specified in the RFC.
Parameters:
Name Type Description
id string schema ID URI
type string type of the credential schema
Source:

setStatus(status) → {VerifiableCredential}

Set a status for this Credential
Parameters:
Name Type Description
status object Status of the credential
Source:
Returns:
Type
VerifiableCredential

setSubject(subject) → {VerifiableCredential}

Set the subject for this Credential
Parameters:
Name Type Description
subject object | array Subject of the credential as object or array
Source:
Returns:
Type
VerifiableCredential

(async) sign(keyDoc, compactProofopt, issuerObjectopt, addSuiteContextopt, typeopt) → {Promise.<VerifiableCredential>}

Sign a Verifiable Credential using the provided keyDoc
Parameters:
Name Type Attributes Default Description
keyDoc object key document containing `id`, `controller`, `type`, `privateKeyBase58` and `publicKeyBase58`
compactProof Boolean <optional>
true Whether to compact the JSON-LD or not.
issuerObject object <optional>
null Optional issuer object to assign
addSuiteContext Boolean <optional>
true Toggles the default behavior of each signature suite enforcing the presence of its own `@context` (if it is not present, it's added to the context list).
type jsonld | jwt | proofValue <optional>
null Optional format/type of the credential (JSON-LD, JWT, proofValue)
Source:
Returns:
Type
Promise.<VerifiableCredential>

toJSON() → {object}

Define the JSON representation of a Verifiable Credential.
Source:
Returns:
Type
object

(async) validateSchema(schema) → {Promise.<Boolean>}

Check that the credential is compliant with given JSON schema, meaning `credentialSubject` has the structure specified by the given JSON schema. Use `validateCredentialSchema` but exclude subject's id. Allows issuer to validate schema before adding it.
Parameters:
Name Type Description
schema object The schema to validate with
Source:
Returns:
Type
Promise.<Boolean>

(async) verify(paramsopt) → {Promise.<VerifiableCredentialVerificationResult>}

Verify a Verifiable Credential
Parameters:
Name Type Attributes Description
params object <optional>
Verify parameters (TODO: add type info for this object)
Source:
Returns:
Type
Promise.<VerifiableCredentialVerificationResult>