{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://qlaas.co.uk/spec/dmi-manifest-0.2.schema.json",
  "title": "Qlaas DMI manifest (schema revision 0.2, wire profile worldauth.dmi.communications/0.1)",
  "description": "The document a line serves at /.well-known/dmi.json. Individual draft; not an adopted standard. Unknown members MUST be ignored by consumers.",
  "type": "object",
  "required": [
    "dmi",
    "generatedAt",
    "resource",
    "capabilities",
    "executionPaths",
    "evidence",
    "signatures"
  ],
  "properties": {
    "dmi": {
      "enum": [
        "worldauth.dmi.communications/0.1"
      ]
    },
    "generatedAt": {
      "type": "string",
      "format": "date-time"
    },
    "resource": {
      "type": "object",
      "required": [
        "kind",
        "principal",
        "line"
      ],
      "properties": {
        "kind": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]*\\.[a-z][a-z0-9-]*$"
        },
        "principal": {
          "type": "object",
          "required": [
            "name"
          ],
          "properties": {
            "name": {
              "type": "string",
              "minLength": 1
            },
            "handle": {
              "type": "string",
              "pattern": "^[a-z0-9_.-]{1,64}$"
            }
          }
        },
        "line": {
          "type": "string",
          "format": "uri"
        },
        "identity": {
          "type": "string",
          "format": "uri"
        },
        "agentCard": {
          "type": "string",
          "format": "uri"
        },
        "addresses": {
          "type": "object",
          "properties": {
            "door": {
              "type": "string",
              "format": "uri"
            },
            "federated": {
              "type": "string",
              "pattern": "^[^@\\s]+@[^@\\s]+$"
            },
            "tel": {
              "type": "string",
              "pattern": "^tel:\\+[0-9]{6,15}$"
            }
          }
        }
      }
    },
    "state": {
      "type": "object",
      "required": [
        "asOf",
        "evidence"
      ],
      "properties": {
        "asOf": {
          "type": "string",
          "format": "date-time"
        },
        "evidence": {
          "enum": [
            "observed",
            "declared"
          ]
        },
        "acceptingCalls": {
          "type": "boolean"
        },
        "ownerReachableNow": {
          "type": "boolean"
        },
        "quietUntil": {
          "type": "string",
          "format": "date-time"
        },
        "preferredForMachines": {
          "type": "string"
        }
      }
    },
    "capabilities": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/capability"
      }
    },
    "executionPaths": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/executionPath"
      }
    },
    "contact": {
      "type": "object",
      "properties": {
        "mode": {
          "enum": [
            "full",
            "message_first"
          ]
        },
        "humans": {
          "enum": [
            "allow",
            "screen",
            "message_only"
          ]
        },
        "headline": {
          "type": "string"
        }
      }
    },
    "upgrade": {
      "type": "object",
      "properties": {
        "description": {
          "type": "string"
        },
        "field": {
          "type": "string"
        }
      }
    },
    "evidence": {
      "type": "object",
      "required": [
        "receipts"
      ],
      "properties": {
        "receipts": {
          "type": "object",
          "required": [
            "alg",
            "canonicalization",
            "keyId",
            "key"
          ],
          "properties": {
            "alg": {
              "const": "EdDSA"
            },
            "canonicalization": {
              "const": "JCS"
            },
            "chained": {
              "type": "boolean"
            },
            "keyId": {
              "type": "string",
              "minLength": 1
            },
            "key": {
              "$ref": "#/$defs/ed25519Jwk"
            },
            "jwks": {
              "type": "string",
              "format": "uri"
            },
            "jwksAliases": {
              "type": "array",
              "items": {
                "type": "string",
                "format": "uri"
              }
            },
            "versions": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "disclosure": {
          "type": "string"
        }
      }
    },
    "discovery": {
      "type": "object",
      "properties": {
        "wellKnown": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "uri"
          }
        },
        "dns": {
          "type": "string"
        },
        "dnsAliases": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "signatures": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "keyId",
          "alg",
          "canonicalization",
          "signature"
        ],
        "properties": {
          "keyId": {
            "type": "string",
            "minLength": 1
          },
          "alg": {
            "const": "EdDSA"
          },
          "canonicalization": {
            "const": "JCS"
          },
          "signature": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]{86}$"
          }
        }
      }
    }
  },
  "$defs": {
    "ed25519Jwk": {
      "type": "object",
      "required": [
        "kty",
        "crv",
        "x"
      ],
      "properties": {
        "kty": {
          "const": "OKP"
        },
        "crv": {
          "const": "Ed25519"
        },
        "x": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{43}$"
        },
        "kid": {
          "type": "string"
        },
        "alg": {
          "const": "EdDSA"
        },
        "use": {
          "const": "sig"
        }
      }
    },
    "capability": {
      "type": "object",
      "required": [
        "id",
        "paths"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]{0,63}$"
        },
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "contract": {
          "type": "object",
          "properties": {
            "input": {
              "type": "object"
            },
            "output": {
              "type": "object"
            }
          }
        },
        "constraints": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "consequences": {
          "type": "string"
        },
        "authority": {
          "type": "object",
          "required": [
            "default"
          ],
          "properties": {
            "default": {
              "enum": [
                "ALLOW",
                "STEP_UP",
                "DENY"
              ]
            },
            "rules": {
              "type": "array",
              "items": {
                "type": "object",
                "required": [
                  "effect"
                ],
                "properties": {
                  "effect": {
                    "enum": [
                      "ALLOW",
                      "STEP_UP",
                      "DENY"
                    ]
                  },
                  "when": {
                    "type": "object",
                    "properties": {
                      "tiers": {
                        "type": "array",
                        "items": {
                          "enum": [
                            "observed",
                            "declared",
                            "verified",
                            "inferred",
                            "verified-intermediary"
                          ]
                        }
                      },
                      "vendors": {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      "maxMinutes": {
                        "type": "integer",
                        "minimum": 1
                      }
                    }
                  }
                }
              }
            },
            "note": {
              "type": "string"
            }
          }
        },
        "paths": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "outcome": {
          "type": "string"
        },
        "evidence": {
          "type": "string"
        }
      }
    },
    "executionPath": {
      "type": "object",
      "required": [
        "rank",
        "id",
        "protocol",
        "for"
      ],
      "properties": {
        "rank": {
          "type": "integer",
          "minimum": 1
        },
        "id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]{0,63}$"
        },
        "protocol": {
          "type": "string",
          "minLength": 1
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "for": {
          "enum": [
            "machines",
            "people"
          ]
        },
        "secondary": {
          "type": "boolean"
        },
        "auth": {
          "type": "array",
          "items": {
            "type": "object",
            "required": [
              "scheme",
              "tier"
            ],
            "properties": {
              "scheme": {
                "type": "string",
                "minLength": 1
              },
              "tier": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        },
        "cdo": {
          "type": "object"
        },
        "evidence": {
          "enum": [
            "declared",
            "observed"
          ]
        },
        "note": {
          "type": "string"
        }
      }
    }
  }
}
