{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://verascore.ai/schemas/verascore-evidence-schema-v0.1.json",
  "title": "Verascore Evidence Ingest Schema v0.1",
  "description": "Request envelope accepted by POST /api/attestations/ingest. The wrapped envelope is the canonical public shape. The endpoint also accepts a flat JWS-only submission when provider metadata can be derived from the JWS protected header and payload.",
  "oneOf": [
    {
      "$ref": "#/$defs/wrappedEnvelope"
    },
    {
      "$ref": "#/$defs/flatJwsEnvelope"
    }
  ],
  "$defs": {
    "compactJws": {
      "type": "string",
      "description": "Compact JWS signed by the provider's registered key. The JWS is verified against the provider JWKS before storage.",
      "pattern": "^[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+$"
    },
    "did": {
      "type": "string",
      "description": "Canonical agent DID. The live endpoint requires this value to start with did: after flat-shape normalization.",
      "pattern": "^did:.+"
    },
    "wrappedEnvelope": {
      "type": "object",
      "description": "Canonical wrapped ingest envelope used by registered providers.",
      "required": [
        "provider",
        "subjectDid",
        "attestationType",
        "scope",
        "jws"
      ],
      "additionalProperties": true,
      "properties": {
        "provider": {
          "type": "string",
          "minLength": 1,
          "description": "Registered AttestationProvider.name. The provider must exist and be active."
        },
        "subjectDid": {
          "$ref": "#/$defs/did"
        },
        "attestationType": {
          "type": "string",
          "minLength": 1,
          "description": "Provider-defined attestation type. Verascore maps this through AttestationProvider.dimensionMap."
        },
        "scope": {
          "type": "string",
          "minLength": 1,
          "description": "Provider-defined evidence scope. Used as a secondary dimensionMap key when attestationType does not match."
        },
        "jws": {
          "$ref": "#/$defs/compactJws"
        },
        "evidenceUrl": {
          "type": "string",
          "format": "uri",
          "description": "Optional URL for source evidence or a human-readable evidence bundle."
        }
      }
    },
    "flatJwsEnvelope": {
      "type": "object",
      "description": "Compatibility shape accepted when provider and subject metadata can be derived from the JWS. Protected header kid must start with a registered active provider name. Payload must contain sub, subject, or did; type or attestationType is optional and defaults to general; scope is optional and defaults to general.",
      "required": [
        "jws"
      ],
      "additionalProperties": true,
      "properties": {
        "jws": {
          "$ref": "#/$defs/compactJws"
        },
        "evidenceUrl": {
          "type": "string",
          "format": "uri",
          "description": "Optional URL for source evidence or a human-readable evidence bundle."
        }
      },
      "not": {
        "properties": {
          "provider": {}
        },
        "required": [
          "provider"
        ]
      }
    }
  }
}
