5.4.0 • Published 19 days ago

@cef-ebsi/verifiable-credential v5.4.0

Weekly downloads
-
License
EUPL-1.2
Repository
-
Last release
19 days ago

EBSI Logo

Verifiable Credential Library

Create and verify EBSI-compliant W3C Verifiable Credentials in JWT format.

This library extends the @transmute/json-web-signature and @transmute/vc.js libraries by applying additional validation rules. For more details, see VC Framework.

Notes:

Table of Contents

  1. Installation
  2. Usage
  3. License

Installation

Using npm:

npm i --save @cef-ebsi/verifiable-credential

Using yarn:

yarn add @cef-ebsi/verifiable-credential

Usage

Creating JWTs

Prerequisites

In order to create a valid JWT, the issuer must either be:

  1. a Legal Entity (did:ebsi method). In this case, the issuer must also be registered in the DID Registry and in the Trusted Issuers Registry.
  2. a Natural Person (did:key method).

Creating a Verifiable Credential as a Legal Entity

Create an EbsiIssuer object to sign JWTs:

import type { EbsiIssuer } from "@cef-ebsi/verifiable-credential";

const issuer = {
  did: "did:ebsi:zxaYaUtb8pvoAtYNWbKcveg",
  kid: "did:ebsi:zxaYaUtb8pvoAtYNWbKcveg#CHxYzOqt38Sx6YBfPYhiEdgcwzWk9ty7k0LBa6h70nc",
  alg: "ES256K",
  publicKeyJwk: {
    kty: "EC",
    crv: "secp256k1",
    x: "YsWJUlskYA_wdyKG8z1LYFICL-KNO7fE3WO5-z7dFa4",
    y: "uo7ddu68ZY7YBreYNY0GQm-bgz6Xf3zXba0Bk0MgMWI",
  },
  privateKeyJwk: {
    kty: "EC",
    crv: "secp256k1",
    x: "YsWJUlskYA_wdyKG8z1LYFICL-KNO7fE3WO5-z7dFa4",
    y: "uo7ddu68ZY7YBreYNY0GQm-bgz6Xf3zXba0Bk0MgMWI",
    d: "<ECC private key>",
  },
} satisfies EbsiIssuer;

Specify a payload matching the EbsiVerifiableAttestation interface:

import {
  createVerifiableCredentialJwt,
  type EbsiVerifiableAttestation,
} from "@cef-ebsi/verifiable-credential";

const vcPayload = {
  "@context": ["https://www.w3.org/2018/credentials/v1"],
  id: "urn:uuid:003a1dd8-a5d2-42ef-8182-e921c0a9f2cd",
  type: ["VerifiableCredential", "VerifiableAttestation"],
  issuer: "did:ebsi:zxaYaUtb8pvoAtYNWbKcveg",
  issuanceDate: "2021-11-01T00:00:00Z",
  validFrom: "2021-11-01T00:00:00Z",
  validUntil: "2050-11-01T00:00:00Z",
  expirationDate: "2031-11-30T00:00:00Z",
  issued: "2021-10-30T00:00:00Z",
  credentialSubject: {
    id: "did:key:z2dmzD81cgPx8Vki7JbuuMmFYrWPgYoytykUZ3eyqht1j9KbsNgeztBFXEB9FUZCoufTjXiTUZYKkcP36i2XAQCphfxBwvXG4dAaF6pdwhrMGyaLMC81fU5ECMnt4VgMQpwh3sn5vSbUpwoaTBME78noXJaTLgkCv5KkM6VgGTfWUjH8Z2",
  },
  credentialSchema: {
    id: "https://api-pilot.ebsi.eu/trusted-schemas-registry/v3/schemas/z3MgUFUkb722uq4x3dv5yAJmnNmzDFeK5UC8x83QoeLJM",
    type: "FullJsonSchemaValidator2021",
  },
  termsOfUse: {
    id: "https://api-pilot.ebsi.eu/trusted-issuers-registry/v5/issuers/did:ebsi:zxaYaUtb8pvoAtYNWbKcveg/attributes/b40fd9b404418a44d2d9911377a03130dde450eb546c755b5b80acd782902e6d",
    type: "IssuanceCertificate",
  },
} satisfies EbsiVerifiableAttestation;

Specify the options to validate the issuer and credential:

import type { CreateVerifiableCredentialOptions } from "@cef-ebsi/verifiable-credential";

const options = {
  // REQUIRED. EBSI URI Authority ([userinfo "@"] host [":" port])
  ebsiAuthority: "api-pilot.ebsi.eu",

  // OPTIONAL. EBSI environment configuration.
  // This option allows you to override the default URLs (TIR, DIDR, TSR).
  ebsiEnvConfig: {
    didRegistry: "https://api-pilot.ebsi.eu/did-registry/v5/identifiers",
    trustedIssuersRegistry:
      "https://api-pilot.ebsi.eu/trusted-issuers-registry/v5/issuers",
    trustedPoliciesRegistry:
      "https://api-pilot.ebsi.eu/trusted-policies-registry/v3/users",
  },

  // OPTIONAL. Timeout after which the requests made by the library will fail. Default: 15 seconds
  timeout: 15_000,

  // OPTIONAL. List of trusted hostnames. To be used if the Core Services APIs are hosted on a custom host for instance.
  // If `trustedHostnames` is not defined, the default trusted domains are: "api-test.ebsi.eu", "api-conformance.ebsi.eu", and "api-pilot.ebsi.eu"
  // trustedHostnames: ["api.example.net"],

  // OPTIONAL. Determines whether to validate the Verifiable Credential payload or not.
  // Validation is active by default.
  // Note: even when skipValidation is set to true, the payload must be a valid EBSI Verifiable Attestation.
  skipValidation: false,

  // OPTIONAL. Determines whether to validate the accreditations of the VC issuer or not.
  // Validation is active by default.
  skipAccreditationsValidation: false,

  // OPTIONAL. Determines whether to validate the credential status or not.
  // Validation is active by default.
  skipStatusValidation: false,
} satisfies CreateVerifiableCredentialOptions;

Create a JWT by signing it with the previously configured issuer using the createVerifiableCredentialJwt function:

const vcJwt = await createVerifiableCredentialJwt(vcPayload, issuer, options);
console.log(vcJwt);
// eyJhbGciOiJFUzI1NksiLCJ0eXAiOiJKV1QiLCJraWQiOiJkaWQ6ZWJzaTp6eGFZYVV0Yjhwdm9BdFlOV2JLY3ZlZyNDSHhZek9xdDM4U3g2WUJmUFloaUVkZ2N3eldrOXR5N2swTEJhNmg3MG5jIn0.eyJqdGkiOiJ1cm46dXVpZDowMDNhMWRkOC1hNWQyLTQyZWYtODE4Mi1lOTIxYzBhOWYyY2QiLCJzdWIiOiJkaWQ6a2V5OnoyZG16RDgxY2dQeDhWa2k3SmJ1dU1tRllyV1BnWW95dHlrVVozZXlxaHQxajlLYnNOZ2V6dEJGWEVCOUZVWkNvdWZUalhpVFVaWUtrY1AzNmkyWEFRQ3BoZnhCd3ZYRzRkQWFGNnBkd2hyTUd5YUxNQzgxZlU1RUNNbnQ0VmdNUXB3aDNzbjV2U2JVcHdvYVRCTUU3OG5vWEphVExna0N2NUtrTTZWZ0dUZldVakg4WjIiLCJpc3MiOiJkaWQ6ZWJzaTp6eGFZYVV0Yjhwdm9BdFlOV2JLY3ZlZyIsIm5iZiI6MTYzNTcyNDgwMCwiZX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nVsbEpzb25TY2hlbWFWYWxpZGF0b3IyMDIxIn0sInRlcm1zT2ZVc2UiOnsiaWQiOiJodHRwczovL2FwaS1waWxvdC5lYnNpLmV1L3RydXN0ZWQtaXNzdWVycy1yZWdpc3RyeS92NS9pc3N1ZXJzL2RpZDplYnNpOnp4YVlhVXRiOHB2b0F0WU5XYktjdmVnL2F0dHJpYnV0ZXMvYjQwZmQ5YjQwNDQxOGE0NGQyZDk5MTEzNzdhMDMxMzBkZGU0NTBlYjU0NmM3NTViNWI4MGFjZDc4MjkwMmU2ZCIsInR5cGUiOiJJc3N1YW5jZUNlcnRpZmljYXRlIn19fQ.I8Im8azp0pSnM4z_jqGTTfYUg7K802POR2LTJftVfjYtMt82Cik2Z_KGOG7dHhx13R6VGVZKg9134ke1bKhtPw

Creating a Verifiable Credential as a Natural Person

Create an EbsiIssuer object to sign JWTs:

import type { EbsiIssuer } from "@cef-ebsi/verifiable-credential";

const issuer = {
  did: "did:key:z2dmzD81cgPx8Vki7JbuuMmFYrWPgYoytykUZ3eyqht1j9KbsALgKJNpKj7U9jdYAHu3nxJ4fonckTBBGWELRpHJZ9dBKRzGebbNYTz6bWtaTM3zyyWnrkfb8w5owU1ECw2W7u1Rz2B5MgocMnnaa9wzDB3paEQvcgth9ErYawbNu9MLLc",
  kid: "did:key:z2dmzD81cgPx8Vki7JbuuMmFYrWPgYoytykUZ3eyqht1j9KbsALgKJNpKj7U9jdYAHu3nxJ4fonckTBBGWELRpHJZ9dBKRzGebbNYTz6bWtaTM3zyyWnrkfb8w5owU1ECw2W7u1Rz2B5MgocMnnaa9wzDB3paEQvcgth9ErYawbNu9MLLc#z2dmzD81cgPx8Vki7JbuuMmFYrWPgYoytykUZ3eyqht1j9KbsALgKJNpKj7U9jdYAHu3nxJ4fonckTBBGWELRpHJZ9dBKRzGebbNYTz6bWtaTM3zyyWnrkfb8w5owU1ECw2W7u1Rz2B5MgocMnnaa9wzDB3paEQvcgth9ErYawbNu9MLLc",
  alg: "ES256",
  publicKeyJwk: {
    kty: "EC",
    x: "myPoRDa5QONxWQ2rB3OJ7ftHlRDWQHhbNH7ra2Y1-i0",
    y: "q00oUQjzvETQkjCM2F22dvChyqXKa0wsiVGLd--yz5Y",
    crv: "P-256",
  },
  privateKeyJwk: {
    kty: "EC",
    x: "myPoRDa5QONxWQ2rB3OJ7ftHlRDWQHhbNH7ra2Y1-i0",
    y: "q00oUQjzvETQkjCM2F22dvChyqXKa0wsiVGLd--yz5Y",
    crv: "P-256",
    d: "nxski1rN7qCb36d0r9oLliyujYEkEmex4YThvx_VOUc",
  },
} satisfies EbsiIssuer;

Specify a payload matching the EbsiVerifiableAttestation interface:

import {
  createVerifiableCredentialJwt,
  type EbsiVerifiableAttestation,
} from "@cef-ebsi/verifiable-credential";

const vcPayload = {
  "@context": ["https://www.w3.org/2018/credentials/v1"],
  id: "urn:uuid:003a1dd8-a5d2-42ef-8182-e921c0a9f2cd",
  type: ["VerifiableCredential", "VerifiableAttestation"],
  issuer:
    "did:key:z2dmzD81cgPx8Vki7JbuuMmFYrWPgYoytykUZ3eyqht1j9KbsALgKJNpKj7U9jdYAHu3nxJ4fonckTBBGWELRpHJZ9dBKRzGebbNYTz6bWtaTM3zyyWnrkfb8w5owU1ECw2W7u1Rz2B5MgocMnnaa9wzDB3paEQvcgth9ErYawbNu9MLLc",
  issuanceDate: "2021-11-01T00:00:00Z",
  validFrom: "2021-11-01T00:00:00Z",
  validUntil: "2050-11-01T00:00:00Z",
  expirationDate: "2031-11-30T00:00:00Z",
  issued: "2021-10-30T00:00:00Z",
  credentialSubject: {
    id: "did:key:z2dmzD81cgPx8Vki7JbuuMmFYrWPgYoytykUZ3eyqht1j9KbrDgYJoht124ErdE8UUmbXR1gE7MnCayN6VZNuVMBZH2MfNVvbHJNYiHfWBWp3E3X5JnJYadaaL8pyJWh1a6JYpAkDKhUtefYDNZcv3BdDMvfp7auC1DVjs8ECRmKPPCw7r",
  },
  credentialSchema: {
    id: "https://api-pilot.ebsi.eu/trusted-schemas-registry/v3/schemas/z3MgUFUkb722uq4x3dv5yAJmnNmzDFeK5UC8x83QoeLJM",
    type: "FullJsonSchemaValidator2021",
  },
} satisfies EbsiVerifiableAttestation;

Specify the options to validate the issuer and credential:

import type { CreateVerifiableCredentialOptions } from "@cef-ebsi/verifiable-credential";

const options = {
  // REQUIRED. EBSI URI Authority ([userinfo "@"] host [":" port])
  ebsiAuthority: "api-pilot.ebsi.eu",

  // OPTIONAL. EBSI environment configuration.
  // This option allows you to override the default URLs (TIR, DIDR, TSR).
  ebsiEnvConfig: {
    didRegistry: "https://api-pilot.ebsi.eu/did-registry/v5/identifiers",
    trustedIssuersRegistry:
      "https://api-pilot.ebsi.eu/trusted-issuers-registry/v5/issuers",
    trustedPoliciesRegistry:
      "https://api-pilot.ebsi.eu/trusted-policies-registry/v3/users",
  },

  // OPTIONAL. Timeout after which the requests made by the library will fail. Default: 15 seconds
  timeout: 15_000,

  // OPTIONAL. List of trusted hostnames. To be used if the Core Services APIs are hosted on a custom host for instance.
  // If `trustedHostnames` is not defined, the default trusted domains are: "api-test.ebsi.eu", "api-conformance.ebsi.eu", and "api-pilot.ebsi.eu"
  trustedHostnames: ["api.example.net"],

  // OPTIONAL. Determines whether to validate the Verifiable Credential payload or not.
  // Validation is active by default.
  // Note: even when skipValidation is set to true, the payload must be a valid EBSI Verifiable Attestation.
  skipValidation: false,

  // OPTIONAL. Determines whether to validate the accreditations of the VC issuer or not.
  // Validation is active by default.
  skipAccreditationsValidation: false,

  // OPTIONAL. Determines whether to validate the credential status or not.
  // Validation is active by default.
  skipStatusValidation: false,
} satisfies CreateVerifiableCredentialOptions;

Create a JWT by signing it with the previously configured issuer using the createVerifiableCredentialJwt function:

const vcJwt = await createVerifiableCredentialJwt(vcPayload, issuer, options);
console.log(vcJwt);
// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImRpZDprZXk6ejJkbXpEODFjZ1B4OFZraTdKYnV1TW1GWXJXUGdZb3l0eW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RlbnRpYWxTY2hlbWEiOnsiaWQiOiJodHRwczovL2FwaS1waWxvdC5lYnNpLmV1L3RydXN0ZWQtc2NoZW1hcy1yZWdpc3RyeS92My9zY2hlbWFzL3ozTWdVRlVrYjcyMnVxNHgzZHY1eUFKbW5ObXpERmVLNVVDOHg4M1FvZUxKTSIsInR5cGUiOiJGdWxsSnNvblNjaGVtYVZhbGlkYXRvcjIwMjEifX19.BArwMltlr61I9Pg_SOtewJJF6IfDbo0I2RHFQtM7JPQ8ZWjmPuIU2sH7SnT1yTPC_xWFvmG363U6DNFChnpvGQ

Verifying JWTs

Prerequisites

Verify a VC JWT using the verifyCredentialJwt function:

import {
  verifyCredentialJwt,
  type VerifyCredentialOptions,
} from "@cef-ebsi/verifiable-credential";

const vcJwt =
  "eyJhbGciOiJFUzI1NksiLCJ0eXAiOiJKV1QiLCJraWQiOiJkaWQ6ZWJzaTp6eGFZYVV0Yjhwdm9BdFlOV2JLY3ZlZyNDSHhZek9xdDM4U3g2WUJmUFloaUVkZ2N3eldrOXR5N2swTEJhNmg3MG5jIn0.eyJqdGkiOiJ1cm46dXVpZDowMDNhMWRkOC1hNWQyLTQyZWYtODE4Mi1lOTIxYzBhOWYyY2QiLCJzdWIiOiJkaWQ6a2V5OnoyZG16RDgxY2dQeDhWa2k3SmJ1dU1tRllyV1BnWW95dHlrVVozZXlxaHQxajlLYnNOZ2V6dEJGWEVCOUZVWkNvdWZUalhpVFVaWUtrY1AzNmkyWEFRQ3BoZnhCd3ZYRzRkQWFGNnBkd2hyTUd5YUxNQzgxZlU1RUNNbnQ0VmdNUXB3aDNzbjV2U2JVcHdvYVRCTUU3OG5vWEphVExna0N2NUtrTTZWZ0dUZldVakg4WjIiLCJpc3MiOiJkaWQ6ZWJzaTp6eGFZYVV0Yjhwdm9BdFlOV2JLY3ZlZyIsIm5iZiI6MTYzNTcyNDgwMCwiZXhwIjoxOTUzNzYzMjAwLCJpYXQiOjE2MzU1NTIwMDAsInZjIjp7IkBjb250ZX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aWQiOiJodHRwczovL2FwaS1waWxvdC5lYnNpLmV1L3RydXN0ZWQtaXNzdWVycy1yZWdpc3RyeS92NS9pc3N1ZXJzL2RpZDplYnNpOnp4YVlhVXRiOHB2b0F0WU5XYktjdmVnL2F0dHJpYnV0ZXMvYjQwZmQ5YjQwNDQxOGE0NGQyZDk5MTEzNzdhMDMxMzBkZGU0NTBlYjU0NmM3NTViNWI4MGFjZDc4MjkwMmU2ZCIsInR5cGUiOiJJc3N1YW5jZUNlcnRpZmljYXRlIn19fQ.I8Im8azp0pSnM4z_jqGTTfYUg7K802POR2LTJftVfjYtMt82Cik2Z_KGOG7dHhx13R6VGVZKg9134ke1bKhtPw";

const options = {
  // REQUIRED. EBSI URI Authority ([userinfo "@"] host [":" port])
  ebsiAuthority: "api-pilot.ebsi.eu",

  // OPTIONAL. EBSI environment configuration.
  // This option allows you to override the default URLs (TIR, DIDR, TSR).
  ebsiEnvConfig: {
    didRegistry: "https://api-pilot.ebsi.eu/did-registry/v5/identifiers",
    trustedIssuersRegistry:
      "https://api-pilot.ebsi.eu/trusted-issuers-registry/v5/issuers",
    trustedPoliciesRegistry:
      "https://api-pilot.ebsi.eu/trusted-policies-registry/v3/users",
  },

  // OPTIONAL. Timeout after which the requests made by the library will fail. Default: 15 seconds
  timeout: 15_000,

  // OPTIONAL. List of trusted hostnames. To be used if the Core Services APIs are hosted on a custom host for instance.
  // If `trustedHostnames` is not defined, the default trusted domains are: "api-test.ebsi.eu", "api-conformance.ebsi.eu", and "api-pilot.ebsi.eu"
  trustedHostnames: ["api.example.net"],

  // OPTIONAL. Unix timestamp. Optional comparison date.
  // For the JWT to be valid, `nbf` ≤ `validAt` ≤ `exp`.
  validAt: 1686048193,

  // OPTIONAL. Determines whether or not to validate the issuer's accreditations when `termsOfUse` is missing. Default: false
  validateAccreditationWithoutTermsOfUse: false,

  // OPTIONAL. Determines whether to validate the accreditations of the VC issuer or not.
  // Validation is active by default.
  skipAccreditationsValidation: false,

  // OPTIONAL. Determines whether to validate the credential status or not.
  // Validation is active by default.
  skipStatusValidation: false,
} satisfies VerifyCredentialOptions;

const verifiedVc = await verifyCredentialJwt(vcJwt, options);

console.log(verifiedVc);
/*
{
  '@context': [ 'https://www.w3.org/2018/credentials/v1' ],
  id: 'urn:uuid:003a1dd8-a5d2-42ef-8182-e921c0a9f2cd',
  type: [ 'VerifiableCredential', 'VerifiableAttestation' ],
  issuer: 'did:ebsi:zxaYaUtb8pvoAtYNWbKcveg',
  issuanceDate: '2021-11-01T00:00:00Z',
  validFrom: '2021-11-01T00:00:00Z',
  validUntil: '2050-11-01T00:00:00Z',
  expirationDate: '2031-11-30T00:00:00Z',
  issued: '2021-10-30T00:00:00Z',
  credentialSubject: {
    id: 'did:key:z2dmzD81cgPx8Vki7JbuuMmFYrWPgYoytykUZ3eyqht1j9KbsNgeztBFXEB9FUZCoufTjXiTUZYKkcP36i2XAQCphfxBwvXG4dAaF6pdwhrMGyaLMC81fU5ECMnt4VgMQpwh3sn5vSbUpwoaTBME78noXJaTLgkCv5KkM6VgGTfWUjH8Z2'
  },
  credentialSchema: {
    id: 'https://api-pilot.ebsi.eu/trusted-schemas-registry/v3/schemas/z3MgUFUkb722uq4x3dv5yAJmnNmzDFeK5UC8x83QoeLJM',
    type: 'FullJsonSchemaValidator2021'
  },
  termsOfUse: {
    id: 'https://api-pilot.ebsi.eu/trusted-issuers-registry/v5/issuers/did:ebsi:zxaYaUtb8pvoAtYNWbKcveg/attributes/b40fd9b404418a44d2d9911377a03130dde450eb546c755b5b80acd782902e6d',
    type: 'IssuanceCertificate'
  }
}
*/

Verification process

The verification of the credentials is performed using the following process:

  1. Header
  • The alg property must be ES256, ES256K, Ed25519, or EdDSA.
  • The kid property must contain the DID of the issuer and the fragment identifier allowing to know which verification method to use.
  1. Basic properties in the payload
  • The payload must contain a vc property containing an EBSI Verifiable Attestation.
  • The iss property must match the VC issuer vc.issuer.
  • The sub property must match the VC credential subject vc.credentialSubject.id.
  • The jti property must match the VC ID vc.id.
  • The iat property must refer to the date in VC issued vc.issued.
  • The nbf property must refer to the date in VC valid from vc.validFrom.
  • The exp property mush refer to date in VC expiration date vc.expirationDate in the case it is defined.
  1. Signature
  • The signature must be validated against the verification method from the DID document corresponding to the VC JWT kid header.
  1. Extra validations to the VC payload
  • Validation of @context.
  • Validation of type.
  • Validation of dates.
  1. Issuer in Trusted Issuers Registry

If the issuer is a Legal Entity:

  • The issuer must be registered in the Trusted Issuers Registry.

Additionally, if the VC is an attestation with accreditation:

  • The VC must contain a termsOfUse property pointing to the accreditations of the issuer.
  • The issuer must be accredited to issue the types present in the credential.
  1. Credential subject
  • The credential subject must be a valid DID, using either the did:ebsi v1 method (Legal Entity) or the did:key method (Natural Person).
  1. Credential schema
  • The VC credential schema(s) must link to valid EBSI credential schemas, registered in the Trusted Schemas Registry.
  • The credential payload is validated against the aforementioned JSON Schemas.

License

Copyright (c) 2019 European Commission
Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European Commission - subsequent versions of the EUPL (the "Licence"); You may not use this work except in compliance with the Licence. You may obtain a copy of the Licence at:

Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Licence for the specific language governing permissions and limitations under the Licence.

5.5.0-alpha.0

19 days ago

5.4.0

28 days ago

5.4.0-alpha.1

1 month ago

5.4.0-alpha.0

2 months ago

5.3.0

2 months ago

5.3.0-alpha.0

2 months ago

5.2.1-alpha.3

2 months ago

5.2.1-alpha.2

2 months ago

5.2.1-alpha.1

3 months ago

5.2.1-alpha.0

3 months ago

5.2.0

3 months ago

5.2.0-alpha.1

3 months ago

5.2.0-alpha.0

4 months ago

5.1.0

4 months ago

5.1.0-alpha.2

4 months ago

5.1.0-alpha.1

4 months ago

5.1.0-alpha.0

4 months ago

5.0.0

6 months ago

5.0.0-alpha.5

7 months ago

5.0.0-alpha.4

7 months ago

5.0.0-alpha.3

7 months ago

5.0.0-alpha.2

8 months ago

5.0.0-alpha.1

8 months ago

5.0.0-alpha.0

8 months ago

4.4.2

11 months ago

4.5.0

10 months ago

4.5.2

7 months ago

4.5.1

10 months ago

4.4.1

12 months ago

4.4.0

12 months ago

4.3.0

1 year ago

4.2.0

1 year ago

4.0.1

1 year ago

4.0.0

1 year ago

4.0.2

1 year ago

4.1.0

1 year ago

4.1.2

1 year ago

4.1.1

1 year ago

4.0.0-alpha.5

1 year ago

4.0.0-alpha.6

1 year ago

4.0.0-alpha.4

1 year ago

4.0.0-alpha.3

1 year ago

4.0.0-alpha.1

1 year ago

4.0.0-alpha.2

1 year ago

4.0.0-alpha.0

1 year ago

3.3.0

1 year ago

3.2.0

1 year ago

3.1.1

1 year ago

3.1.0

2 years ago

3.0.0-rc.0

2 years ago

3.0.0

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

2.0.0-alpha.3

2 years ago

2.0.2

2 years ago

2.0.0-alpha.1

2 years ago

2.0.0-alpha.2

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.3.0

2 years ago

2.0.0-alpha.0

2 years ago

1.2.0

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.1.2

2 years ago

1.0.0-rc.11

2 years ago

1.0.0-rc.9

3 years ago

1.0.0-rc.10

3 years ago

1.0.0-rc.7

3 years ago

1.0.0-rc.8

3 years ago

1.0.0-rc.6

3 years ago

1.0.0-rc.5

3 years ago

1.0.0-rc.4

3 years ago

1.0.0-rc.3

3 years ago

1.0.0-rc.2

3 years ago

1.0.0-rc.1

3 years ago

1.0.0-rc.0

3 years ago