{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://weverlabs.com/schemas/agent-credential-envelope.schema.json",
  "title": "Agent Credential Envelope",
  "description": "Structured envelope for returning credential metadata, scope, retrieval instructions, and delivery proof. Secret values are delivered through the protected OS channel named by the envelope, not embedded in public examples.",
  "type": "object",
  "required": [
    "envelope_id",
    "credential_type",
    "agent_id",
    "access_key_id",
    "retrieval_mode",
    "credential_status",
    "scope",
    "links"
  ],
  "properties": {
    "envelope_id": {
      "type": "string"
    },
    "credential_type": {
      "type": "string",
      "enum": [
        "agent_access_key",
        "callback_token",
        "signed_status_token",
        "provider_scoped_token"
      ]
    },
    "agent_id": {
      "type": "string"
    },
    "access_key_id": {
      "type": "string"
    },
    "credential_status": {
      "type": "string",
      "enum": [
        "issued",
        "retrieval_ready",
        "retrieved",
        "active",
        "rotated",
        "revoked",
        "expired"
      ]
    },
    "retrieval_mode": {
      "type": "string",
      "enum": [
        "callback_delivery",
        "contact_channel",
        "one_time_retrieval",
        "system_to_system_exchange"
      ]
    },
    "masked_key_hint": {
      "type": "string"
    },
    "issued_at": {
      "type": "string",
      "format": "date-time"
    },
    "expires_at": {
      "type": "string",
      "format": "date-time"
    },
    "scope": {
      "type": "object",
      "properties": {
        "allowed_tools": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "allowed_endpoints": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "credit_account_id": {
          "type": "string"
        },
        "contract_id": {
          "type": "string"
        },
        "rate_limit_profile": {
          "type": "string"
        }
      },
      "additionalProperties": true
    },
    "delivery_proof": {
      "type": "object",
      "properties": {
        "delivery_id": {
          "type": "string"
        },
        "delivered_to": {
          "type": "string"
        },
        "delivered_at": {
          "type": "string",
          "format": "date-time"
        },
        "callback_status": {
          "type": "string"
        }
      },
      "additionalProperties": true
    },
    "links": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    }
  },
  "additionalProperties": true
}
