{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://usedeed.app/contracts/deed.proof_card.v2.schema.json",
  "title": "DEED proof card v2",
  "description": "A bounded, self-issued DEED proof card. Verification code remains authoritative for cryptographic, revocation, and formal-tree checks.",
  "type": "object",
  "required": [
    "schema",
    "cardId",
    "mark",
    "markBasis",
    "issuer",
    "subject",
    "selfIssued",
    "head",
    "issuedAt",
    "expiresAt",
    "custodyInvariant",
    "revocation",
    "controls",
    "formalTreeHash",
    "sig"
  ],
  "properties": {
    "schema": { "const": "https://usedeed.app/contracts/deed.proof_card.v2.schema.json" },
    "cardId": { "type": "string", "pattern": "^zvpc_sha256_[0-9a-f]{64}$" },
    "mark": { "enum": ["ZV-Custody", "ZV-Bounded", "ZV-Attested", "ZV-Sovereign"] },
    "markBasis": {
      "type": "object",
      "required": ["level", "controls"],
      "properties": {
        "level": { "enum": ["ZV-Custody", "ZV-Bounded", "ZV-Attested", "ZV-Sovereign"] },
        "controls": { "type": "array", "items": { "type": "string" }, "uniqueItems": true }
      },
      "additionalProperties": false
    },
    "issuer": {
      "type": "object",
      "required": ["type", "entity"],
      "properties": {
        "type": { "const": "self" },
        "entity": { "const": "DEED" }
      },
      "additionalProperties": false
    },
    "subject": {
      "type": "object",
      "required": ["type", "entity", "agents", "repo", "head"],
      "properties": {
        "type": { "const": "self" },
        "entity": { "const": "DEED" },
        "agents": { "const": "DEED first-party agents" },
        "repo": { "const": "degenie-xyz/factory" },
        "head": { "type": "string", "pattern": "^[0-9a-f]{40}$" }
      },
      "additionalProperties": false
    },
    "selfIssued": { "const": true },
    "head": { "type": "string", "pattern": "^[0-9a-f]{40}$" },
    "issuedAt": { "type": "string", "format": "date-time" },
    "expiresAt": { "type": "string", "format": "date-time" },
    "custodyInvariant": { "const": "self-custody only; DEED never holds keys; signing remains delegated off-system" },
    "revocation": {
      "oneOf": [
        {
          "type": "object",
          "required": ["type", "schema", "path", "uri"],
          "properties": {
            "type": { "const": "file" },
            "schema": { "const": "https://usedeed.app/contracts/deed.proof_card.revocations.v1.schema.json" },
            "path": { "const": "governance/zv-revocations.json" },
            "uri": { "const": "governance/zv-revocations.json" }
          },
          "additionalProperties": false
        },
        {
          "type": "object",
          "required": ["type", "schema", "chain", "registry", "method", "selector", "cardIdHash"],
          "properties": {
            "type": { "const": "onchain" },
            "schema": { "const": "https://usedeed.app/contracts/deed.proof_card.onchain_revocation.v1.schema.json" },
            "chain": { "type": "object" },
            "registry": { "type": "object" },
            "method": { "const": "isRevoked(bytes32)" },
            "selector": { "const": "0x4294857f" },
            "cardIdHash": { "type": "string", "pattern": "^0x[0-9a-fA-F]{64}$" }
          },
          "additionalProperties": true
        }
      ]
    },
    "controls": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "command", "exitCode"],
        "properties": {
          "id": { "type": "string", "minLength": 1 },
          "command": { "type": "string", "minLength": 1 },
          "exitCode": { "type": "integer" }
        },
        "additionalProperties": true
      },
      "minItems": 1
    },
    "formalTreeHash": {
      "type": "object",
      "required": ["algorithm", "value", "fileCount", "lock", "closure", "vendorDir", "cubicalCommit"],
      "properties": {
        "algorithm": { "type": "string", "minLength": 1 },
        "value": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
        "fileCount": { "type": "integer", "minimum": 1 },
        "lock": { "type": "string", "minLength": 1 },
        "closure": { "type": "string", "minLength": 1 },
        "vendorDir": { "type": "string", "minLength": 1 },
        "cubicalCommit": { "type": "string", "pattern": "^[0-9a-f]{40}$" }
      },
      "additionalProperties": false
    },
    "externalAttestations": { "type": "array", "items": { "type": "object" } },
    "sig": {
      "type": "object",
      "required": ["alg", "keyId", "value", "publicKeyJwk"],
      "properties": {
        "alg": { "const": "ECDSA-P256-SHA256" },
        "keyId": { "type": "string", "minLength": 1 },
        "value": { "type": "string", "minLength": 1 },
        "publicKeyJwk": {
          "type": "object",
          "required": ["kty", "crv", "x", "y"],
          "properties": {
            "kty": { "const": "EC" },
            "crv": { "const": "P-256" },
            "x": { "type": "string", "minLength": 1 },
            "y": { "type": "string", "minLength": 1 },
            "d": false
          },
          "additionalProperties": true
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": true
}
