{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.nuqasm.com/docs/audit-record-schema.json",
  "title": "Nuqasm Audit Record",
  "description": "Cryptographically signed execution provenance record for regulated quantum workloads. Maps to NIST SP 800-53 AU-3, AU-9, AU-10, AU-11 and 21 CFR Part 11 §11.10(e).",
  "type": "object",
  "required": ["schemaVersion", "recordId", "submitter", "workload", "execution", "ledger", "signatures"],
  "properties": {
    "schemaVersion": {
      "type": "string",
      "const": "2.0.0",
      "description": "Schema version for forward compatibility"
    },
    "recordId": {
      "type": "string",
      "format": "uuid",
      "description": "Unique identifier for this audit record"
    },
    "submitter": {
      "type": "object",
      "required": ["identity", "signatureAlgorithm", "publicKeyFingerprint"],
      "properties": {
        "identity": { "type": "string", "description": "Named individual (Part 11 §11.200)" },
        "organization": { "type": "string" },
        "signatureAlgorithm": { "type": "string", "enum": ["ML-DSA-87", "ML-DSA-65"] },
        "publicKeyFingerprint": { "type": "string" },
        "submittedAt": { "type": "string", "format": "date-time" }
      }
    },
    "workload": {
      "type": "object",
      "required": ["circuitHash", "sourceFormat", "policyBlock"],
      "properties": {
        "circuitHash": { "type": "string", "description": "SHA-256 of canonical circuit representation" },
        "sourceFormat": { "type": "string", "enum": ["qiskit", "pennylane", "openqasm", "qasm3"] },
        "policyBlock": {
          "type": "object",
          "properties": {
            "allowedEnvironments": { "type": "array", "items": { "type": "string" } },
            "retentionYears": { "type": "integer", "minimum": 1 },
            "classification": { "type": "string" }
          }
        },
        "qcapArchiveUri": { "type": "string", "description": "Reference to sealed .qcap archive" }
      }
    },
    "execution": {
      "type": "object",
      "required": ["environment", "backend", "startedAt", "completedAt", "outcome"],
      "properties": {
        "environment": { "type": "string", "enum": ["simulator", "cloud-routing", "air-gapped-appliance"] },
        "backend": { "type": "string", "description": "e.g. ibm_quantum:ibm_kyoto, ionq:harmony, amazon_braket:rigetti_ankaa_3, rigetti:ankaa_3, quantinuum:h2, uqbench:de10-nano" },
        "calibrationSnapshot": {
          "type": "object",
          "properties": {
            "capturedAt": { "type": "string", "format": "date-time" },
            "gateFidelities": { "type": "object" },
            "readoutError": { "type": "number" }
          }
        },
        "transpileChain": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "stage": { "type": "string" },
              "hash": { "type": "string" }
            }
          }
        },
        "startedAt": { "type": "string", "format": "date-time" },
        "completedAt": { "type": "string", "format": "date-time" },
        "outcome": { "type": "string", "enum": ["success", "failure", "cancelled"] },
        "resultHash": { "type": "string" }
      }
    },
    "ledger": {
      "type": "object",
      "required": ["chainPointer", "retentionPolicy", "immutable"],
      "properties": {
        "chainPointer": { "type": "string", "description": "Previous record hash for append-only chain (AU-9)" },
        "retentionPolicy": { "type": "string", "enum": ["1yr", "3yr", "7yr+"] },
        "immutable": { "type": "boolean", "const": true },
        "exportFormats": { "type": "array", "items": { "type": "string", "enum": ["pdf", "csv", "json"] } }
      }
    },
    "signatures": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["algorithm", "value", "signedFields"],
        "properties": {
          "algorithm": { "type": "string" },
          "value": { "type": "string" },
          "signedFields": { "type": "array", "items": { "type": "string" } },
          "signedAt": { "type": "string", "format": "date-time" }
        }
      }
    },
    "controlMapping": {
      "type": "object",
      "description": "Optional explicit control satisfaction references",
      "properties": {
        "nist80053": { "type": "array", "items": { "type": "string" } },
        "part11": { "type": "array", "items": { "type": "string" } },
        "cnsa20": { "type": "boolean" }
      }
    }
  }
}
