{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "id": "https://github.com/ml-learning/digital-certificates-schema/certificate-schema-v1.json",
  "title": "Certificate schema V1.1",
  "type": "object",
  "properties": {
    "certificate": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "format": "uri",
          "description": "URI link to a JSON that describes the type of certificate. Default format is https://[domain]/criteria/[year]/[month]/[certificate_title].json."
        },
        "image": {
          "type": "string",
          "description": "A base-64 encoded png image of the certificate's image.",
          "pattern": "data:image\/png;base64,"
        },
        "language": {
          "type": "string",
          "description": "Represents the ieft language and ieft country codes. Format is [ieft_language]-[IEFT_COUNTRY]. Backcompatible change to make this field not required.",
          "pattern": "[a-z]{2}-[A-Z]{2}"
        },
        "subtitle": {
          "type": "object",
          "description": "Subtitle of the certificate.",
          "properties": {
            "content": {
              "type": "string",
              "description": "Content of the subtitle."
            },
            "display": {
              "oneOf": [
                {
                  "type": "string"
                },
               {
                 "type": "boolean"
                }
              ],
              "description": "Flag that indicates whether to show or hide the subtitle in the viewer. Backcompatible change to allow 2 types that occurred in the wild before proper validation."
            }
          },
          "required": [
            "content",
            "display"
          ],
          "additionalProperties": false
        },
        "title": {
          "type": "string",
          "description": "Title of the certificate."
        },
        "issuer": {
          "type": "object",
          "description": "Details about the issuer of the certificate.",
          "properties": {
            "image": {
              "type": "string",
              "description": "A base-64 encoded png image of the issuer's logo.",
              "pattern": "data:image\/png;base64,"
            },
            "id": {
              "type": "string",
              "format": "uri",
              "description": "Link to a JSON that details the issuer's issuing and recovation keys. Default is https://[domain]/issuer/[org_abbr]-issuer.json. Included for (near) backward compatibility with open badges specification 1.1"
            },
            "url": {
              "type": "string",
              "format": "uri",
              "description": "URI of the issuer's homepage"
            },
            "name": {
              "type": "string",
              "description": "Name of the issuer."
            },
            "email": {
              "type": "string",
              "format": "email",
              "description": "Email address of the issuer."
            }
          },
          "required": [
            "image",
            "id",
            "url",
            "name",
            "email"
          ],
          "additionalProperties": false
        },
        "description": {
          "type": "string",
          "description": "Description of what the certificate represents. Usually one - three sentences long."
        }
      },
      "additionalProperties": false,
      "required": [
        "id",
        "image",
        "subtitle",
        "title",
        "issuer",
        "description"
      ]
    },
    "assertion": {
      "type": "object",
      "properties": {
        "evidence": {
          "type": "string",
          "description": "Text, uri, etc. that shows evidence of the recipient's learning that the certificate represents. Can be left as an empty string if not used."
        },
        "uid": {
          "type": "string",
          "description": "Unique identifier. By default it is created using the string of a BSON ObjectId(), yielding an identifier 24 characters long."
        },
        "issuedOn": {
          "type": "string",
          "format": "date-time",
          "description": "Date the the certificate JSON was created."
        },
        "id": {
          "type": "string",
          "format": "uri",
          "description": "URI that links to the certificate on the viewer. Default is https://[domain]/[uid]"
        },
        "image:signature": {
          "type": "string",
          "description": "A base-64 encoded png image of the issuer's signature.",
          "pattern": "data:image\/png;base64,"
        }
      },
      "required": [
        "evidence",
        "uid",
        "issuedOn",
        "id",
        "image:signature"
      ],
      "additionalProperties": false
    },
    "verify": {
      "type": "object",
      "properties": {
        "attribute-signed": {
          "type": "string",
          "description": "Name of the attribute in the json that is signed by the issuer's private key. Default is 'uid', referring to the uid attribute."
        },
        "type": {
          "type": "string",
          "description": "Name of the signing method. Default is 'ECDSA(secp256k1)', referring to the Bitcoin method of signing messages with the issuer's private key."
        },
        "signer": {
          "type": "string",
          "format": "uri",
          "description": "URI where issuer's public key is presented. Default is https://[domain]/keys/[org-abbr]-certs-public-key.asc. Compatible with open badges specification v1.1. Ideally, we would change this to point to a JSON instead, so we could retire keys (similar to the way we handle the issuer ID), but for now we're sticking with the OBS 1.1."
        }
      },
      "required": [
        "attribute-signed",
        "type",
        "signer"
      ],
      "additionalProperties": false
    },
    "recipient": {
      "type": "object",
      "properties": {
        "familyName": {
          "type": "string",
          "description": "Family name of the recipient."
        },
        "identity": {
          "type": "string",
          "description": "String that represents a recipient's identity. By default, it is an email address."
        },
        "type": {
          "type": "string",
          "description": "Type of value in the identity field. Default is 'email'."
        },
        "hashed": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "boolean"
            }
          ],
          "description": "Describes if the value in the identity field is hashed or not. Default is false, indicating that the identity is not hashed. Backcompatible change to allow 2 types that occurred in the wild before proper validation."
        },
        "pubkey": {
          "type": "string",
          "description": "Bitcoin address (compressed public key, usually 24 characters) of the recipient."
        },
        "givenName": {
          "type": "string",
          "description": "Given name of the recipient"
        }
      },
      "required": [
        "familyName",
        "identity",
        "type",
        "hashed",
        "pubkey",
        "givenName"
      ],
      "additionalProperties": false
    },
    "signature": {
      "type": "string",
      "description": "String of signature created when the Bitcoin private key signs the value in the attribute-signed field."
    },
    "extension": {
      "type": "object",
      "description": "Extension object that includes extra fields not in the standard.",
      "properties": {
        "assertion": {
          "type": "object",
          "properties": {}
          },
        "verify": {
          "type": "object",
          "properties": {}
          },
        "certificate": {
          "type": "object",
          "properties": {}
          },
        "recipient": {
          "type": "object",
          "properties": {}
        }
      }
    }
  },
  "required": [
    "certificate",
    "assertion",
    "verify",
    "recipient"
  ],
  "additionalProperties": false
}
