{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://kotoba.cloud/.well-known/kotoba-org-membership-schema/v1.json",
  "title": "KotobaOrgMembership/v1",
  "description": "W3C Verifiable Credential schema: membership of a principal DID in a kotoba.cloud organization DID. Issuer is the organization; subject is the member principal. Verified together with the org's webvh document, the credential status list and the kotoba-org-registry issuer entry.",
  "type": "object",
  "required": ["@context", "type", "issuer", "issuanceDate", "credentialSubject", "credentialStatus"],
  "properties": {
    "@context": {
      "type": "array",
      "minItems": 2,
      "items": { "type": "string", "format": "uri" }
    },
    "id": { "type": "string", "format": "uri" },
    "type": {
      "type": "array",
      "contains": { "const": "VerifiableCredential" },
      "minItems": 2,
      "items": { "type": "string" }
    },
    "issuer": {
      "type": "string",
      "pattern": "^did:webvh:"
    },
    "issuanceDate": { "type": "string", "format": "date-time" },
    "expirationDate": { "type": "string", "format": "date-time" },
    "credentialSubject": {
      "type": "object",
      "required": ["id", "org", "role"],
      "properties": {
        "id": {
          "type": "string",
          "description": "Member principal DID (stable principal, did:key-family).",
          "pattern": "^did:"
        },
        "org": {
          "type": "string",
          "pattern": "^did:webvh:",
          "description": "The organization DID; must equal the issuer."
        },
        "role": {
          "type": "string",
          "enum": ["owner", "admin", "member", "billing"]
        },
        "handle": {
          "type": "string",
          "pattern": "^com-[a-z0-9-]+\\.kotoba\\.cloud$"
        }
      }
    },
    "credentialStatus": {
      "type": "object",
      "required": ["id", "type"],
      "properties": {
        "id": { "type": "string", "format": "uri" },
        "type": { "type": "string" }
      }
    },
    "proof": {
      "type": "object",
      "required": ["type", "created", "verificationMethod", "proofPurpose"],
      "properties": {
        "type": { "type": "string" },
        "created": { "type": "string", "format": "date-time" },
        "verificationMethod": { "type": "string" },
        "proofPurpose": { "type": "string", "const": "assertionMethod" },
        "jws": { "type": "string" }
      }
    }
  }
}
