zk

package
v1.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package zchain provides the Z-Chain (Privacy) adapter for DAG indexing. Z-Chain uses DAG consensus for fast finality combined with ZK proofs for privacy.

Index

Constants

View Source
const (
	// DefaultRPCEndpoint for Z-Chain
	DefaultRPCEndpoint = "http://localhost:9650/ext/bc/Z/rpc"
	// DefaultHTTPPort for Z-Chain indexer API
	DefaultHTTPPort = 4400
	// DefaultDatabase for Z-Chain explorer
	DefaultDatabase = "explorer_zchain"
	// RPCMethod prefix for Z-Chain
	RPCMethod = "zvm"
)

Variables

This section is empty.

Functions

func DefaultConfig

func DefaultConfig() dag.Config

DefaultConfig returns the default configuration for Z-Chain indexer

func ValidateCommitmentHash

func ValidateCommitmentHash(hash string) error

ValidateCommitmentHash validates a commitment hash format

func ValidateNullifierHash

func ValidateNullifierHash(hash string) error

ValidateNullifierHash validates a nullifier hash format

Types

type Adapter

type Adapter struct {
	// contains filtered or unexported fields
}

Adapter implements dag.Adapter for Z-Chain

func New

func New(rpcEndpoint string) *Adapter

New creates a new Z-Chain adapter

func (*Adapter) GetCommitment

func (a *Adapter) GetCommitment(ctx context.Context, hash string) (*Commitment, error)

GetCommitment fetches commitment status

func (*Adapter) GetMerkleRoot

func (a *Adapter) GetMerkleRoot(ctx context.Context) (string, error)

GetMerkleRoot fetches the current commitment tree root

func (*Adapter) GetNullifier

func (a *Adapter) GetNullifier(ctx context.Context, hash string) (*Nullifier, error)

GetNullifier fetches nullifier status

func (*Adapter) GetRecentVertices

func (a *Adapter) GetRecentVertices(ctx context.Context, limit int) ([]json.RawMessage, error)

GetRecentVertices fetches recent vertices from RPC

func (*Adapter) GetStats

func (a *Adapter) GetStats(ctx context.Context, store storage.Store) (map[string]interface{}, error)

GetStats returns Z-Chain specific statistics

func (*Adapter) GetVertexByID

func (a *Adapter) GetVertexByID(ctx context.Context, id string) (json.RawMessage, error)

GetVertexByID fetches a specific vertex

func (*Adapter) InitSchema

func (a *Adapter) InitSchema(ctx context.Context, store storage.Store) error

InitSchema creates Z-Chain specific database tables

func (*Adapter) ParseVertex

func (a *Adapter) ParseVertex(data json.RawMessage) (*dag.Vertex, error)

ParseVertex parses RPC response into a DAG vertex

func (*Adapter) StoreTransfer

func (a *Adapter) StoreTransfer(ctx context.Context, store storage.Store, t ShieldedTransfer, vertexID string) error

StoreTransfer stores a shielded transfer and its components

func (*Adapter) UpdateExtendedStats

func (a *Adapter) UpdateExtendedStats(ctx context.Context, store storage.Store) error

UpdateExtendedStats updates Z-Chain specific statistics

func (*Adapter) VerifyProof

func (a *Adapter) VerifyProof(ctx context.Context, proof ZKProof) (bool, error)

VerifyProof verifies a ZK proof on-chain

type Commitment

type Commitment struct {
	Hash      string `json:"hash"`
	TxID      string `json:"txId"`
	Index     int    `json:"index"`
	CreatedAt int64  `json:"createdAt,omitempty"` // Vertex height
	Spent     bool   `json:"spent"`
}

Commitment represents a shielded note commitment

type Nullifier

type Nullifier struct {
	Hash    string `json:"hash"`
	TxID    string `json:"txId"`
	Index   int    `json:"index"`
	SpentAt int64  `json:"spentAt,omitempty"` // Vertex height
}

Nullifier represents a spent note marker (prevents double-spending)

type ProofType

type ProofType string

ProofType identifies ZK proof systems

const (
	ProofGroth16 ProofType = "groth16"
	ProofPlonk   ProofType = "plonk"
	ProofSTARK   ProofType = "stark"
	ProofBullet  ProofType = "bulletproof"
	ProofHalo2   ProofType = "halo2"
	ProofFRI     ProofType = "fri" // Fast Reed-Solomon IOP
)

type RPCError

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

RPCError in JSON-RPC response

type RPCRequest

type RPCRequest struct {
	JSONRPC string        `json:"jsonrpc"`
	ID      int           `json:"id"`
	Method  string        `json:"method"`
	Params  []interface{} `json:"params,omitempty"`
}

RPCRequest for JSON-RPC calls

type RPCResponse

type RPCResponse struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      int             `json:"id"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *RPCError       `json:"error,omitempty"`
}

RPCResponse from JSON-RPC calls

type ShieldedTransfer

type ShieldedTransfer struct {
	TxID         string            `json:"txId"`
	Type         ZKTransactionType `json:"type"`
	Proof        ZKProof           `json:"proof"`
	Nullifiers   []Nullifier       `json:"nullifiers"`
	Commitments  []Commitment      `json:"commitments"`
	ValueBalance int64             `json:"valueBalance,omitempty"` // Net flow for shield/unshield
	Fee          uint64            `json:"fee"`
	Memo         string            `json:"memo,omitempty"` // Encrypted memo
	Timestamp    time.Time         `json:"timestamp"`
}

ShieldedTransfer represents a private transfer

type VertexData

type VertexData struct {
	Transfers     []ShieldedTransfer `json:"transfers,omitempty"`
	MerkleRoot    string             `json:"merkleRoot"`    // Commitment tree root
	NullifierRoot string             `json:"nullifierRoot"` // Nullifier set root
	Epoch         uint32             `json:"epoch"`
	Proposer      string             `json:"proposer,omitempty"`
}

VertexData holds Z-Chain specific vertex payload

type ZKProof

type ZKProof struct {
	Type         ProofType `json:"type"`
	Data         string    `json:"data"` // Hex-encoded proof bytes
	PublicInputs []string  `json:"publicInputs,omitempty"`
	VerifyingKey string    `json:"verifyingKey,omitempty"`
}

ZKProof represents a zero-knowledge proof

type ZKTransactionType

type ZKTransactionType string

ZKTransactionType identifies privacy transaction types

const (
	TxShieldedTransfer ZKTransactionType = "shielded_transfer"
	TxShield           ZKTransactionType = "shield"   // Deposit: transparent -> shielded
	TxUnshield         ZKTransactionType = "unshield" // Withdraw: shielded -> transparent
	TxJoinSplit        ZKTransactionType = "joinsplit"
	TxMint             ZKTransactionType = "mint"
	TxBurn             ZKTransactionType = "burn"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL