VerifiablePresentation is a tamper-evident presentation encoded in such a way that authorship of the data can be trusted after a process of cryptographic verification. W3C Verifiable Presentation Data Model.

It provides functionalities to sign, verify, and create presentations, offering a concise API to work with JWT representations of verifiable presentations and ensuring that the signatures and claims within those JWTs can be validated.

Constructors

Properties

vpDataModel: IPresentation

The [vpDataModel] instance representing the core data model of a verifiable presentation.

Accessors

  • get holder(): string
  • The holder of the Verifiable Presentation.

    Returns string

  • get type(): string
  • The type of the Verifiable Presentation.

    Returns string

  • get verifiableCredential(): string[]
  • The verifiable credentials contained in the Verifiable Presentation.

    Returns string[]

Methods

  • Signs the verifiable presentation and returns it as a signed JWT.

    Parameters

    Returns Promise<string>

    The JWT representing the signed verifiable presentation.

    Example

    const vpJwt = verifiablePresentation.sign({ did: myDid });
    
  • Converts the current object to its JSON representation.

    Returns string

    The JSON representation of the object.

  • Create a [VerifiablePresentation] based on the provided parameters.

    Parameters

    Returns Promise<VerifiablePresentation>

    A [VerifiablePresentation] instance.

    Example

    const vp = await VerifiablePresentation.create({
    type: 'PresentationSubmission',
    holder: 'did:ex:holder',
    vcJwts: vcJwts,
    additionalData: { 'arbitrary': 'data' }
    })
  • Parses a JWT into a [VerifiablePresentation] instance.

    Parameters

    • vpJwt: {
          vpJwt: string;
      }

      The verifiable presentation JWT as a [String].

      • vpJwt: string

    Returns VerifiablePresentation

    A [VerifiablePresentation] instance derived from the JWT.

    Example

    const vp = VerifiablePresentation.parseJwt({ vpJwt: signedVpJwt })
    
  • Verifies the integrity and authenticity of a Verifiable Presentation (VP) encoded as a JSON Web Token (JWT).

    This function performs several crucial validation steps to ensure the trustworthiness of the provided VP:

    • Parses and validates the structure of the JWT.
    • Ensures the presence of critical header elements alg and kid in the JWT header.
    • Resolves the Decentralized Identifier (DID) and retrieves the associated DID Document.
    • Validates the DID and establishes a set of valid verification method IDs.
    • Identifies the correct Verification Method from the DID Document based on the kid parameter.
    • Verifies the JWT's signature using the public key associated with the Verification Method.

    If any of these steps fail, the function will throw a [Error] with a message indicating the nature of the failure.

    Parameters

    • vpJwt: {
          vpJwt: string;
      }

      The Verifiable Presentation in JWT format as a [string].

      • vpJwt: string

    Returns Promise<{
        issuer: string;
        subject: string;
        vp: IPresentation;
    }>

    Example

    try {
    VerifiablePresentation.verify({ vpJwt: signedVpJwt })
    console.log("VC Verification successful!")
    } catch (e: Error) {
    console.log("VC Verification failed: ${e.message}")
    }

    Throws

    Error if the verification fails at any step, providing a message with failure details.

    Throws

    Error if critical JWT header elements are absent.