{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:orbiplex:schema:contact-claim:v1",
  "title": "ContactClaim v1",
  "description": "Opt-in Contact Catalog claim using an ordered lookup-safe owner route set. Raw handles are not stored in this artifact.",
  "type": "object",
  "additionalProperties": true,
  "x-dia-workflow": "project",
  "x-dia-status": "draft",
  "x-dia-basis": [
    "doc/project/40-proposals/058-contact-catalog.md",
    "doc/project/30-stories/story-010-message-to-a-friend.md",
    "doc/schemas/routing-subject-binding.v1.schema.json"
  ],
  "required": [
    "schema",
    "schema/v",
    "claim/id",
    "contact/kind",
    "contact/index",
    "contact/attestation-ref",
    "contact/attested-at",
    "contact/attestation-expires-at",
    "owner/routes",
    "disclosure/mode",
    "purposes",
    "issued/at",
    "expires/at",
    "sequence/no",
    "proof/signature"
  ],
  "properties": {
    "schema": { "const": "contact-claim.v1" },
    "schema/v": { "const": 1 },
    "claim/id": {
      "type": "string",
      "pattern": "^contact-claim:[a-z0-9][a-z0-9:-]*$"
    },
    "contact/kind": {
      "type": "string",
      "enum": ["phone", "email", "other"]
    },
    "contact/index": { "$ref": "#/$defs/contactIndex" },
    "contact/attestation-ref": {
      "type": "string",
      "minLength": 1
    },
    "contact/attested-at": {
      "type": "string",
      "format": "date-time"
    },
    "contact/attestation-expires-at": {
      "type": "string",
      "format": "date-time"
    },
    "owner/routes": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/ownerRoute" }
    },
    "owner/participant-id": {
      "type": "string",
      "pattern": "^participant:did:key:z[1-9A-HJ-NP-Za-km-z]+$",
      "description": "Disclosure-gated root participant id. It MUST NOT be returned by default Contact Catalog lookup profiles."
    },
    "disclosure/mode": {
      "type": "string",
      "enum": ["private-lookup", "invite-only", "public-handle", "present-on-demand"]
    },
    "purposes": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "enum": ["contact", "inbox", "direct-delivery", "messaging", "recovery"]
      }
    },
    "issued/at": {
      "type": "string",
      "format": "date-time"
    },
    "expires/at": {
      "type": "string",
      "format": "date-time"
    },
    "sequence/no": {
      "type": "integer",
      "minimum": 1
    },
    "revocation/ref": {
      "type": ["string", "null"],
      "minLength": 1
    },
    "policy/ref": {
      "type": "string",
      "minLength": 1
    },
    "proof/signature": { "$ref": "#/$defs/signature" }
  },
  "$defs": {
    "contactIndex": {
      "type": "object",
      "additionalProperties": false,
      "required": ["mode", "value"],
      "properties": {
        "mode": {
          "type": "string",
          "enum": ["normalized-digest", "keyed-digest", "blinded-digest", "psi"]
        },
        "value": {
          "type": "string",
          "minLength": 16
        },
        "alg": {
          "type": "string",
          "minLength": 1
        },
        "kid": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "ownerRoute": {
      "type": "object",
      "additionalProperties": false,
      "required": ["route/type"],
      "properties": {
        "route/type": {
          "type": "string",
          "enum": ["routing-subject", "contact-nym", "invitation-route"]
        },
        "routing-subject/id": {
          "type": ["string", "null"],
          "pattern": "^routing:did:key:z[1-9A-HJ-NP-Za-km-z]+$"
        },
        "contact-nym/id": {
          "type": ["string", "null"],
          "pattern": "^contact-nym:[a-z0-9][a-z0-9:-]*$"
        },
        "invitation-route": {
          "anyOf": [
            { "$ref": "#/$defs/invitationRoute" },
            { "type": "null" }
          ]
        },
        "purposes": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "enum": ["contact", "inbox", "direct-delivery", "messaging", "recovery"]
          }
        },
        "valid/until": {
          "type": ["string", "null"],
          "format": "date-time"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": { "route/type": { "const": "routing-subject" } },
            "required": ["route/type"]
          },
          "then": { "required": ["routing-subject/id"] }
        },
        {
          "if": {
            "properties": { "route/type": { "const": "contact-nym" } },
            "required": ["route/type"]
          },
          "then": { "required": ["contact-nym/id"] }
        },
        {
          "if": {
            "properties": { "route/type": { "const": "invitation-route" } },
            "required": ["route/type"]
          },
          "then": { "required": ["invitation-route"] }
        }
      ]
    },
    "invitationRoute": {
      "type": "object",
      "additionalProperties": true,
      "required": ["route/id", "node/id"],
      "properties": {
        "route/id": {
          "type": "string",
          "minLength": 1
        },
        "node/id": {
          "type": "string",
          "pattern": "^node:did:key:z[1-9A-HJ-NP-Za-km-z]+$"
        },
        "valid/until": {
          "type": ["string", "null"],
          "format": "date-time"
        }
      }
    },
    "signature": {
      "type": "object",
      "additionalProperties": true,
      "required": ["alg", "value"],
      "properties": {
        "alg": { "const": "ed25519" },
        "signer": {
          "type": "string",
          "pattern": "^(participant|node|routing|contact-nym):"
        },
        "value": {
          "type": "string",
          "minLength": 1
        }
      }
    }
  }
}
