/*
   Copyright IBM Corp. All Rights Reserved.

   SPDX-License-Identifier: Apache-2.0
*/

syntax = "proto3";

package fabric_token_sdk.token.zkatdlog.v1;

import "common.proto";
import "ftactions.proto";
import "noghmath.proto";

option go_package = "github.com/LFDT-Panurus/panurus/token/core/zkatdlog/nogh/protos-go/v1/actions";

// Token represents a privacy-preserving token using zero-knowledge proofs.
// The token data is a Pedersen commitment hiding the type and value.
message Token {
  // owner is the serialized identity of the token owner
  bytes owner = 1;
  // data is the Pedersen commitment to the token's type and value, providing privacy
  G1 data = 2;
}

// TokenMetadata contains the private information about a token that only
// the owner knows. This is never transmitted on-chain.
message TokenMetadata {
  // type is the token type identifier (e.g., "USD", "EUR")
  string type = 1;
  // value is the quantity of the token as a field element
  Zr value = 2;
  // blinding_factor is the randomness used in the Pedersen commitment
  Zr blinding_factor = 3;
  // issuer is the identity of the token issuer, if applicable
  fabric_token_sdk.token.driver.v1.Identity issuer = 4;
}

// TransferActionInput represents an input token being spent in a privacy-preserving transfer.
message TransferActionInput {
  // token_id uniquely identifies the token being spent
  fabric_token_sdk.token.driver.v1.TokenID token_id = 1;
  // input is the token being spent
  Token input = 2;
  // upgrade_witness contains data needed when upgrading from cleartext to privacy tokens
  TransferActionInputUpgradeWitness upgrade_witness = 3;
}

// TransferActionInputUpgradeWitness provides the information needed to upgrade
// a cleartext fabtoken to a privacy-preserving zkatdlog token.
message TransferActionInputUpgradeWitness {
  // output is the cleartext token being upgraded
  fabric_token_sdk.token.fabtoken.v1.Token output = 1;
  // blinding_factor is the randomness to use in the new commitment
  Zr blinding_factor = 2;
}

// TransferActionOutput represents a newly created privacy-preserving token.
message TransferActionOutput {
  // token is the newly created token
  Token token = 1;
}

// Proof contains a zero-knowledge proof demonstrating the validity of an action.
// It can use either the standard proof system or the CSP-based proof system.
message Proof {
  // proof_type determines which proof system is used
  oneof proof_type {
    // proof is the standard zero-knowledge proof
    bytes proof = 1;
    // csp_based_proof is the CSP (Constraint Satisfaction Problem) based proof
    bytes csp_based_proof = 2;
  }
}

// TransferAction represents a privacy-preserving token transfer that spends existing
// tokens and creates new tokens while proving correctness without revealing amounts.
message TransferAction {
  // version is the protocol version of this transfer action
  uint32 version = 1;
  // inputs are the tokens being spent in this transfer
  repeated TransferActionInput inputs = 2;
  // outputs are the newly created tokens from this transfer
  repeated TransferActionOutput outputs = 3;
  // proof is the zero-knowledge proof that the transfer is valid (inputs = outputs by type)
  Proof proof = 4;
  // metadata contains application-specific data for this transfer
  map<string, bytes> metadata = 5;
  // issuer is the identity that signs the transfer action in redeem scenarios
  fabric_token_sdk.token.driver.v1.Identity issuer = 6;
}

// IssueActionInput represents a token being redeemed (burned) during issuance.
message IssueActionInput {
  // id is the token identifier of the token being redeemed
  fabric_token_sdk.token.driver.v1.TokenID id = 1;
  // token is the serialized token being redeemed
  bytes token = 2;
}

// IssueActionOutput represents a newly issued privacy-preserving token.
message IssueActionOutput {
  // token is the newly issued token
  Token token = 1;
}

// IssueAction represents a privacy-preserving token issuance where an authorized
// issuer creates new tokens with zero-knowledge proofs of validity.
message IssueAction {
  // version is the protocol version of this issue action
  uint32 version = 1;
  // issuer is the identity of the authorized issuer creating these tokens
  fabric_token_sdk.token.driver.v1.Identity issuer = 2;
  // inputs are the tokens being redeemed (if any) during this issuance
  repeated IssueActionInput inputs = 3;
  // outputs are the newly issued tokens
  repeated IssueActionOutput outputs = 4;
  // proof is the zero-knowledge proof that the issuance is valid
  Proof proof = 5;
  // metadata contains application-specific data for this issuance
  map<string, bytes> metadata = 6;
}
