/**
 * Synor Privacy SDK Types
 */

/** Privacy SDK configuration */
export interface PrivacyConfig {
  /** API key for authentication */
  apiKey: string;
  /** API endpoint (defaults to production) */
  endpoint?: string;
  /** Request timeout in milliseconds */
  timeout?: number;
  /** Number of retries for failed requests */
  retries?: number;
  /** Enable debug logging */
  debug?: boolean;
}

/** Public key representation */
export interface PublicKey {
  /** Hex-encoded public key */
  key: string;
  /** Key type */
  type: 'ed25519' | 'secp256k1';
}

/** Private key representation (for signing operations) */
export interface PrivateKey {
  /** Hex-encoded private key */
  key: string;
  /** Key type */
  type: 'ed25519' | 'secp256k1';
}

/** UTXO for confidential transaction input */
export interface ConfidentialUTXO {
  /** Transaction hash */
  txid: string;
  /** Output index */
  vout: number;
  /** Commitment to the amount */
  commitment: string;
  /** Range proof */
  rangeProof: string;
  /** Blinding factor (private) */
  blinding?: string;
  /** Clear amount (private, known only to owner) */
  amount?: string;
}

/** Output for confidential transaction */
export interface ConfidentialOutput {
  /** Recipient stealth address or public key */
  recipient: string;
  /** Amount to send */
  amount: string;
  /** Optional blinding factor (generated if not provided) */
  blinding?: string;
}

/** Confidential transaction */
export interface ConfidentialTransaction {
  /** Transaction ID */
  txid: string;
  /** Version */
  version: number;
  /** Inputs with commitments */
  inputs: ConfidentialTxInput[];
  /** Outputs with commitments */
  outputs: ConfidentialTxOutput[];
  /** Kernel with signature */
  kernel: TransactionKernel;
  /** Transaction offset for signature aggregation */
  offset: string;
  /** Raw transaction hex */
  raw: string;
}

/** Confidential transaction input */
export interface ConfidentialTxInput {
  /** Reference to previous output */
  outputRef: string;
  /** Commitment */
  commitment: string;
}

/** Confidential transaction output */
export interface ConfidentialTxOutput {
  /** Pedersen commitment to the amount */
  commitment: string;
  /** Bulletproof range proof */
  rangeProof: string;
  /** Output features */
  features: OutputFeatures;
}

/** Output features for confidential transactions */
export interface OutputFeatures {
  /** Feature flags */
  flags: number;
  /** Lock height (if time-locked) */
  lockHeight?: number;
}

/** Transaction kernel for confidential transactions */
export interface TransactionKernel {
  /** Kernel features */
  features: number;
  /** Transaction fee */
  fee: string;
  /** Lock height */
  lockHeight: number;
  /** Excess commitment */
  excess: string;
  /** Excess signature */
  excessSignature: string;
}

/** Create confidential transaction options */
export interface CreateConfidentialTxOptions {
  /** Input UTXOs */
  inputs: ConfidentialUTXO[];
  /** Outputs to create */
  outputs: ConfidentialOutput[];
  /** Transaction fee */
  fee?: string;
  /** Lock height */
  lockHeight?: number;
}

/** Confidential transaction verification result */
export interface VerifyConfidentialTxResult {
  /** Whether the transaction is valid */
  valid: boolean;
  /** Verification details */
  details: {
    /** Commitments balance (inputs = outputs + fee) */
    commitmentsBalance: boolean;
    /** All range proofs are valid */
    rangeProofsValid: boolean;
    /** Kernel signature is valid */
    signatureValid: boolean;
    /** No duplicate inputs */
    noDuplicateInputs: boolean;
  };
  /** Error message if invalid */
  error?: string;
}

/** Ring signature */
export interface RingSignature {
  /** Signature ID */
  id: string;
  /** Message hash that was signed */
  messageHash: string;
  /** Ring members (public keys) */
  ring: string[];
  /** Key image (for double-spend prevention) */
  keyImage: string;
  /** Signature components */
  signature: {
    /** Challenge values */
    c: string[];
    /** Response values */
    r: string[];
  };
  /** Ring size */
  ringSize: number;
}

/** Create ring signature options */
export interface CreateRingSignatureOptions {
  /** Message to sign (hex or string) */
  message: string;
  /** Ring of public keys (must include signer's key) */
  ring: string[];
  /** Signer's private key */
  privateKey: string;
  /** Index of signer's key in ring (for optimization) */
  signerIndex?: number;
}

/** Verify ring signature options */
export interface VerifyRingSignatureOptions {
  /** Ring signature to verify */
  signature: RingSignature;
  /** Original message */
  message: string;
}

/** Ring signature verification result */
export interface VerifyRingSignatureResult {
  /** Whether the signature is valid */
  valid: boolean;
  /** Key image (can be used to detect double-signing) */
  keyImage: string;
}

/** Stealth address */
export interface StealthAddress {
  /** One-time public address */
  address: string;
  /** Scan public key (for detecting incoming payments) */
  scanPublicKey: string;
  /** Spend public key */
  spendPublicKey: string;
}

/** Stealth address keypair */
export interface StealthKeypair {
  /** Stealth address */
  address: StealthAddress;
  /** Scan private key */
  scanPrivateKey: string;
  /** Spend private key */
  spendPrivateKey: string;
}

/** One-time address derived from stealth address */
export interface OneTimeAddress {
  /** The one-time address */
  address: string;
  /** Ephemeral public key (included in transaction) */
  ephemeralPublicKey: string;
  /** Shared secret (for sender) */
  sharedSecret?: string;
}

/** Derive shared secret options */
export interface DeriveSharedSecretOptions {
  /** Stealth address */
  stealthAddress: StealthAddress;
  /** Private key for derivation */
  privateKey: string;
  /** Ephemeral public key from transaction */
  ephemeralPublicKey: string;
}

/** Shared secret result */
export interface SharedSecret {
  /** The derived shared secret (hex) */
  secret: string;
  /** One-time private key for spending */
  oneTimePrivateKey: string;
  /** One-time address */
  oneTimeAddress: string;
}

/** Pedersen commitment */
export interface Commitment {
  /** Commitment value (hex) */
  commitment: string;
  /** Generator point used */
  generator: 'default' | 'alternate';
}

/** Create commitment options */
export interface CreateCommitmentOptions {
  /** Value to commit to */
  value: string;
  /** Blinding factor (hex) - generated if not provided */
  blinding?: string;
}

/** Commitment with blinding factor */
export interface CommitmentWithBlinding {
  /** The commitment */
  commitment: Commitment;
  /** Blinding factor used (hex) */
  blinding: string;
}

/** Open commitment options */
export interface OpenCommitmentOptions {
  /** Commitment to open/verify */
  commitment: string;
  /** Claimed value */
  value: string;
  /** Blinding factor */
  blinding: string;
}

/** Bulletproof range proof */
export interface RangeProof {
  /** Proof data (hex) */
  proof: string;
  /** Commitment the proof is for */
  commitment: string;
  /** Bit length of the range */
  bitLength: number;
}

/** Create range proof options */
export interface CreateRangeProofOptions {
  /** Value to prove is in range */
  value: string;
  /** Blinding factor */
  blinding: string;
  /** Optional message to embed in proof */
  message?: string;
  /** Bit length (default 64) */
  bitLength?: number;
}

/** Verify range proof result */
export interface VerifyRangeProofResult {
  /** Whether the proof is valid */
  valid: boolean;
  /** Minimum value in range (usually 0) */
  minValue: string;
  /** Maximum value in range */
  maxValue: string;
}

/** Blinding factor sum options */
export interface BlindingSumOptions {
  /** Positive blinding factors (inputs) */
  positive: string[];
  /** Negative blinding factors (outputs) */
  negative: string[];
}
