{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://synor.io/schemas/privacy.json",
  "title": "Synor Privacy SDK",
  "description": "Confidential transactions, ring signatures, stealth addresses, and commitments",

  "$defs": {
    "PrivacyConfig": {
      "type": "object",
      "allOf": [{ "$ref": "common.json#/$defs/SynorConfig" }]
    },

    "Commitment": {
      "type": "object",
      "properties": {
        "value": { "type": "string", "description": "Commitment value (hex)" },
        "blindingFactor": { "type": "string", "description": "Blinding factor (hex)" }
      },
      "required": ["value"]
    },

    "RangeProof": {
      "type": "object",
      "properties": {
        "proof": { "type": "string", "description": "Bulletproof range proof (hex)" },
        "commitment": { "$ref": "#/$defs/Commitment" }
      },
      "required": ["proof", "commitment"]
    },

    "ConfidentialOutput": {
      "type": "object",
      "properties": {
        "address": { "$ref": "common.json#/$defs/Address" },
        "commitment": { "$ref": "#/$defs/Commitment" },
        "rangeProof": { "$ref": "#/$defs/RangeProof" },
        "encryptedAmount": { "type": "string" }
      },
      "required": ["address", "commitment", "rangeProof"]
    },

    "ConfidentialTransaction": {
      "type": "object",
      "properties": {
        "txid": { "$ref": "common.json#/$defs/TxHash" },
        "inputs": {
          "type": "array",
          "items": { "$ref": "common.json#/$defs/UTXO" }
        },
        "outputs": {
          "type": "array",
          "items": { "$ref": "#/$defs/ConfidentialOutput" }
        },
        "fee": { "$ref": "common.json#/$defs/Amount" },
        "proof": { "type": "string" }
      },
      "required": ["inputs", "outputs"]
    },

    "CreateConfidentialTxRequest": {
      "type": "object",
      "properties": {
        "inputs": {
          "type": "array",
          "items": { "$ref": "common.json#/$defs/UTXO" }
        },
        "outputs": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "address": { "$ref": "common.json#/$defs/Address" },
              "amount": { "$ref": "common.json#/$defs/Amount" }
            },
            "required": ["address", "amount"]
          }
        }
      },
      "required": ["inputs", "outputs"]
    },

    "RingSignature": {
      "type": "object",
      "properties": {
        "keyImage": { "type": "string" },
        "c": {
          "type": "array",
          "items": { "type": "string" }
        },
        "r": {
          "type": "array",
          "items": { "type": "string" }
        },
        "ringSize": { "type": "integer" }
      },
      "required": ["keyImage", "c", "r", "ringSize"]
    },

    "CreateRingSignatureRequest": {
      "type": "object",
      "properties": {
        "message": { "type": "string" },
        "messageFormat": {
          "type": "string",
          "enum": ["text", "hex", "base64"],
          "default": "hex"
        },
        "ring": {
          "type": "array",
          "items": { "$ref": "common.json#/$defs/PublicKey" },
          "minItems": 2
        },
        "secretIndex": { "type": "integer" }
      },
      "required": ["message", "ring"]
    },

    "VerifyRingSignatureRequest": {
      "type": "object",
      "properties": {
        "signature": { "$ref": "#/$defs/RingSignature" },
        "message": { "type": "string" },
        "ring": {
          "type": "array",
          "items": { "$ref": "common.json#/$defs/PublicKey" }
        }
      },
      "required": ["signature", "message", "ring"]
    },

    "StealthAddress": {
      "type": "object",
      "properties": {
        "address": { "$ref": "common.json#/$defs/Address" },
        "viewKey": { "$ref": "common.json#/$defs/PublicKey" },
        "spendKey": { "$ref": "common.json#/$defs/PublicKey" },
        "ephemeralKey": { "$ref": "common.json#/$defs/PublicKey" }
      },
      "required": ["address", "viewKey", "spendKey"]
    },

    "GenerateStealthAddressResponse": {
      "type": "object",
      "properties": {
        "stealthAddress": { "$ref": "#/$defs/StealthAddress" },
        "sharedSecret": { "type": "string" }
      },
      "required": ["stealthAddress"]
    },

    "DeriveSharedSecretRequest": {
      "type": "object",
      "properties": {
        "stealthAddress": { "$ref": "#/$defs/StealthAddress" },
        "privateKey": { "type": "string" }
      },
      "required": ["stealthAddress", "privateKey"]
    },

    "SharedSecret": {
      "type": "object",
      "properties": {
        "secret": { "type": "string" },
        "derivedKey": { "type": "string" }
      },
      "required": ["secret"]
    },

    "CreateCommitmentRequest": {
      "type": "object",
      "properties": {
        "value": { "$ref": "common.json#/$defs/Amount" },
        "blinding": { "type": "string", "description": "Optional blinding factor (hex)" }
      },
      "required": ["value"]
    },

    "CreateCommitmentResponse": {
      "type": "object",
      "properties": {
        "commitment": { "$ref": "#/$defs/Commitment" },
        "blindingFactor": { "type": "string" }
      },
      "required": ["commitment", "blindingFactor"]
    },

    "OpenCommitmentRequest": {
      "type": "object",
      "properties": {
        "commitment": { "$ref": "#/$defs/Commitment" },
        "value": { "$ref": "common.json#/$defs/Amount" },
        "blinding": { "type": "string" }
      },
      "required": ["commitment", "value", "blinding"]
    },

    "OpenCommitmentResponse": {
      "type": "object",
      "properties": {
        "valid": { "type": "boolean" }
      },
      "required": ["valid"]
    },

    "ZeroKnowledgeProof": {
      "type": "object",
      "properties": {
        "proofType": {
          "type": "string",
          "enum": ["groth16", "plonk", "bulletproofs", "stark"]
        },
        "proof": { "type": "string" },
        "publicInputs": {
          "type": "array",
          "items": { "type": "string" }
        },
        "verificationKey": { "type": "string" }
      },
      "required": ["proofType", "proof"]
    },

    "VerifyZkProofRequest": {
      "type": "object",
      "properties": {
        "proof": { "$ref": "#/$defs/ZeroKnowledgeProof" },
        "publicInputs": {
          "type": "array",
          "items": { "type": "string" }
        }
      },
      "required": ["proof"]
    },

    "VerifyZkProofResponse": {
      "type": "object",
      "properties": {
        "valid": { "type": "boolean" },
        "error": { "type": "string" }
      },
      "required": ["valid"]
    }
  }
}
