circuits

package module
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0, MIT Imports: 13 Imported by: 10

README

go-circuits

Go Reference Go Report Card

General description:

The library goal is to create a wrapper for private and public inputs for identity circuits

Repository of circuits implementation: https://github.com/iden3/circuits

Set of functionality for circuits inputs preparation, and public signals schema retrieving

How to use :
  • All circuits implement InputsMarshaller and PubSignalsUnmarshal Interfaces

    type InputsMarshaller interface {
        InputsMarshal() ([]byte, error)
    }
    
    
    type PubSignalsUnmarshaller interface {
        PubSignalsUnmarshal(data []byte) error
    }
    
  • Example of usage:

At the moment you have to fill all needed attributes for a specific Inputs, take a look in test for each specific Input

  inputs := AuthInputs{
        ID: identifier,
        AuthClaim: Claim{
            Claim:       claim,
            Proof:       claimEntryMTP,
            TreeState:   treeState,
            NonRevProof: &ClaimNonRevStatus{treeState, claimNonRevMTP},
        },
        Signature: signature,
        Challenge: challenge,
    }

    circuitInputJSON, err := inputs.InputsMarshal() // marshal JSON inputs for specific circuit in proper format
  • It’s easy to extend Circuits mapping through registering custom Circuit Wrapper implementation

    RegisterCircuit(CustomCircuitID, Data{
        Input:  CustomInputs{},
        Output: &CustomPubSignals{},
    })
    
    Querying :

    The library defines the Query structure for atomic circuits and contains the mapping between query operation and its number. This library is not responsible for resolving SlotIndex for the claim field.

    // Query represents basic request to claim slot verification
    type Query struct {
        SlotIndex int
        Value     *big.Int
        Operator  int
    }
    
    
    // QueryOperators represents operators for atomic circuits
    var QueryOperators = map[string]int{
        "$noop": NOOP,
        "$eq":   EQ,
        "$lt":   LT,
        "$gt":   GT,
        "$in":   IN,
        "$nin":  NIN,
        "$ne":   NE,
    }
    

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as below, without any additional terms or conditions.

License

© 2023 0kims Association

This project is licensed under either of

at your option.

Documentation

Index

Constants

View Source
const (
	ErrorEmptyAuthClaimProof             = "empty auth claim mtp proof"
	ErrorEmptyAuthClaimInNewStateProof   = "empty auth claim in new state mtp proof"
	ErrorEmptyAuthClaimNonRevProof       = "empty auth claim non-revocation mtp proof"
	ErrorEmptyChallengeSignature         = "empty challenge signature"
	ErrorEmptyClaimSignature             = "empty claim signature"
	ErrorEmptyClaimProof                 = "empty claim mtp proof"
	ErrorEmptyClaimNonRevProof           = "empty claim non-revocation mtp proof"
	ErrorEmptyIssuerAuthClaimProof       = "empty issuer auth claim mtp proof"
	ErrorEmptyIssuerClaim                = "empty issuer claim"
	ErrorEmptyStateCommitmentClaim       = "empty state commitment claim"
	ErrorEmptyIssuerAuthClaimNonRevProof = "empty issuer auth claim non-revocation mtp proof"
	ErrorEmptyJsonLDQueryProof           = "empty JSON-LD query mtp proof"
	ErrorEmptyJsonLDQueryValue           = "empty JSON-LD query value"
	ErrorEmptyJsonLDQueryPath            = "empty JSON-LD query path"
	ErrorEmptyQueryValue                 = "empty query value"
	ErrorEmptyJsonLDQueryValues          = "empty JSON-LD query values"
	ErrorEmptyID                         = "empty ID"
	ErrorEmptyChallenge                  = "empty challenge"
	ErrorEmptyGISTProof                  = "empty GIST identity mtp proof"
	ErrorEmptyRequestID                  = "empty request ID"
	ErrorEmptyLinkNonce                  = "empty link nonce"
	ErrorEmptyClaim                      = "empty claim"
	ErrorEmptyQueries                    = "empty queries"
	ErrorTooManyQueries                  = "too many queries"
	ErrorInvalidProofType                = "invalid proof type"
	ErrorEmptySignatureProof             = "empty signature proof"
	ErrorEmptyMTPProof                   = "empty MTP proof"
	ErrorInvalidValuesArrSize            = "invalid query Values array size"
)
View Source
const (
	NOOP int = iota // No operation, skip query verification in circuit
	EQ
	LT
	GT
	IN
	NIN
	NE
	LTE
	GTE
	BETWEEN
	NONBETWEEN
	EXISTS
	SD      = 16
	NULLIFY = 17
)

List of available operators.

View Source
const BatchSize = 5

BatchSize defined by poseidon hash implementation in Solidity

View Source
const LinkedMultiQueryLength = 10

Variables

View Source
var ErrorCircuitIDNotFound = errors.New("circuit id not supported")

ErrorCircuitIDNotFound returns if CircuitID is not registered

View Source
var QueryOperators = map[string]int{
	"$noop":       NOOP,
	"$eq":         EQ,
	"$lt":         LT,
	"$gt":         GT,
	"$in":         IN,
	"$nin":        NIN,
	"$ne":         NE,
	"$lte":        LTE,
	"$gte":        GTE,
	"$between":    BETWEEN,
	"$nonbetween": NONBETWEEN,
	"$exists":     EXISTS,
	"$sd":         SD,
	"$nullify":    NULLIFY,
}

QueryOperators represents operators for atomic circuits

Functions

func CircomSiblings

func CircomSiblings(proof *merkletree.Proof, levels int) []*merkletree.Hash

CircomSiblingsFromSiblings returns the full siblings compatible with circom

func HashToStr

func HashToStr(siblings []*merkletree.Hash) []string

func PoseidonHashValue

func PoseidonHashValue(values []*big.Int) (*big.Int, error)

PoseidonHashValue returns the solidity and circom implementation of poseidon hash

func PrepareCircuitArrayValues

func PrepareCircuitArrayValues(arr []*big.Int, size int) ([]*big.Int, error)

PrepareCircuitArrayValues padding values to size. Validate array size and throw an exception if array is bigger than size if array is bigger circuit cannot compile because number of inputs does not match

func PrepareSiblings

func PrepareSiblings(siblings []*merkletree.Hash, levels int) []*big.Int

PrepareSiblings prepare siblings for zk zk

func PrepareSiblingsStr

func PrepareSiblingsStr(siblings []*merkletree.Hash, levels int) []string

func RegisterCircuit

func RegisterCircuit(id CircuitID, c Data)

RegisterCircuit is factory for circuit init. This is done during init() in the method's implementation

func UnmarshalCircuitOutput

func UnmarshalCircuitOutput(id CircuitID, b []byte) (map[string]interface{}, error)

UnmarshalCircuitOutput unmarshal bytes to specific circuit Output type associated with id

Types

type AtomicQueryMTPInputs

type AtomicQueryMTPInputs struct {
	BaseConfig
	// auth
	ID        *core.ID
	AuthClaim ClaimWithMTPProof
	Challenge *big.Int
	Signature *babyjub.Signature

	Claim ClaimWithMTPProof // claim issued for user

	CurrentTimeStamp int64

	// query
	Query
}

AtomicQueryMTPInputs ZK private inputs for credentialAtomicQueryMTP.circom Deprecated: use AtomicQueryMTPV2Inputs instead

func (AtomicQueryMTPInputs) InputsMarshal

func (a AtomicQueryMTPInputs) InputsMarshal() ([]byte, error)

InputsMarshal returns Circom private inputs for credentialAtomicQueryMTP.circom

type AtomicQueryMTPPubSignals

type AtomicQueryMTPPubSignals struct {
	BaseConfig
	UserID                 *core.ID         `json:"userID"`
	UserState              *merkletree.Hash `json:"userState"`
	Challenge              *big.Int         `json:"challenge"`
	ClaimSchema            core.SchemaHash  `json:"claimSchema"`
	IssuerClaimIdenState   *merkletree.Hash `json:"issuerClaimIdenState"`
	IssuerClaimNonRevState *merkletree.Hash `json:"issuerClaimNonRevState"`
	IssuerID               *core.ID         `json:"issuerID"`
	SlotIndex              int              `json:"slotIndex"`
	Values                 []*big.Int       `json:"values"`
	Operator               int              `json:"operator"`
	Timestamp              int64            `json:"timestamp"`
}

AtomicQueryMTPPubSignals public signals Deprecated: use AtomicQueryMTPV2PubSignals instead

func (AtomicQueryMTPPubSignals) GetObjMap

func (ao AtomicQueryMTPPubSignals) GetObjMap() map[string]interface{}

GetObjMap returns struct field as a map

func (*AtomicQueryMTPPubSignals) PubSignalsUnmarshal

func (ao *AtomicQueryMTPPubSignals) PubSignalsUnmarshal(data []byte) error

PubSignalsUnmarshal unmarshal credentialAtomicQueryMTP.circom public signals array to AtomicQueryMTPPubSignals

type AtomicQueryMTPV2Inputs

type AtomicQueryMTPV2Inputs struct {
	BaseConfig
	// auth
	ID                       *core.ID
	ProfileNonce             *big.Int
	ClaimSubjectProfileNonce *big.Int

	Claim                    ClaimWithMTPProof // claim issued for user
	SkipClaimRevocationCheck bool

	RequestID *big.Int

	CurrentTimeStamp int64

	// query
	Query
}

AtomicQueryMTPV2Inputs ZK private inputs for credentialAtomicQueryMTPV2.circom

func (AtomicQueryMTPV2Inputs) InputsMarshal

func (a AtomicQueryMTPV2Inputs) InputsMarshal() ([]byte, error)

InputsMarshal returns Circom private inputs for credentialAtomicQueryMTP.circom

func (AtomicQueryMTPV2Inputs) Validate

func (a AtomicQueryMTPV2Inputs) Validate() error

Validate validates AtomicQueryMTPPubSignals

type AtomicQueryMTPV2OnChainInputs

type AtomicQueryMTPV2OnChainInputs struct {
	BaseConfig
	// auth
	ID                       *core.ID
	ProfileNonce             *big.Int
	ClaimSubjectProfileNonce *big.Int

	Claim                    ClaimWithMTPProof // claim issued for user
	SkipClaimRevocationCheck bool

	RequestID *big.Int

	CurrentTimeStamp int64

	AuthClaim *core.Claim `json:"authClaim"`

	AuthClaimIncMtp    *merkletree.Proof `json:"authClaimIncMtp"`
	AuthClaimNonRevMtp *merkletree.Proof `json:"authClaimNonRevMtp"`
	TreeState          TreeState         `json:"treeState"`

	GISTProof GISTProof `json:"gistProof"`

	Signature *babyjub.Signature `json:"signature"`
	Challenge *big.Int           `json:"challenge"`

	// query
	Query
}

AtomicQueryMTPV2OnChainInputs ZK private inputs for credentialAtomicQueryMTPV2OnChain.circom

func (AtomicQueryMTPV2OnChainInputs) InputsMarshal

func (a AtomicQueryMTPV2OnChainInputs) InputsMarshal() ([]byte, error)

InputsMarshal returns Circom private inputs for credentialAtomicQueryMTP.circom

func (AtomicQueryMTPV2OnChainInputs) Validate

func (a AtomicQueryMTPV2OnChainInputs) Validate() error

Validate validates AtomicQueryMTPPubSignals

type AtomicQueryMTPV2OnChainPubSignals

type AtomicQueryMTPV2OnChainPubSignals struct {
	BaseConfig
	RequestID              *big.Int         `json:"requestID"`
	UserID                 *core.ID         `json:"userID"`
	IssuerID               *core.ID         `json:"issuerID"`
	IssuerClaimIdenState   *merkletree.Hash `json:"issuerClaimIdenState"`
	IssuerClaimNonRevState *merkletree.Hash `json:"issuerClaimNonRevState"`
	Timestamp              int64            `json:"timestamp"`
	Merklized              int              `json:"merklized"`
	IsRevocationChecked    int              `json:"isRevocationChecked"` // 0 revocation not check, // 1 for check revocation
	QueryHash              *big.Int         `json:"circuitQueryHash"`
	Challenge              *big.Int         `json:"challenge"`
	GlobalRoot             *merkletree.Hash `json:"gistRoot"`
}

AtomicQueryMTPPubSignals public signals

func (AtomicQueryMTPV2OnChainPubSignals) GetObjMap

func (ao AtomicQueryMTPV2OnChainPubSignals) GetObjMap() map[string]interface{}

GetObjMap returns struct field as a map

func (*AtomicQueryMTPV2OnChainPubSignals) PubSignalsUnmarshal

func (ao *AtomicQueryMTPV2OnChainPubSignals) PubSignalsUnmarshal(data []byte) error

PubSignalsUnmarshal unmarshal credentialAtomicQueryMTPV2OnChain.circom public signals array to AtomicQueryMTPPubSignals

type AtomicQueryMTPV2PubSignals

type AtomicQueryMTPV2PubSignals struct {
	BaseConfig
	RequestID              *big.Int         `json:"requestID"`
	UserID                 *core.ID         `json:"userID"`
	IssuerID               *core.ID         `json:"issuerID"`
	IssuerClaimIdenState   *merkletree.Hash `json:"issuerClaimIdenState"`
	IssuerClaimNonRevState *merkletree.Hash `json:"issuerClaimNonRevState"`
	ClaimSchema            core.SchemaHash  `json:"claimSchema"`
	SlotIndex              int              `json:"slotIndex"`
	Operator               int              `json:"operator"`
	Value                  []*big.Int       `json:"value"`
	Timestamp              int64            `json:"timestamp"`
	Merklized              int              `json:"merklized"`
	ClaimPathKey           *big.Int         `json:"claimPathKey"`
	ClaimPathNotExists     int              `json:"claimPathNotExists"`  // 0 for inclusion, 1 for non-inclusion
	IsRevocationChecked    int              `json:"isRevocationChecked"` // 0 revocation not check, // 1 for check revocation
}

AtomicQueryMTPPubSignals public signals

func (AtomicQueryMTPV2PubSignals) GetObjMap

func (ao AtomicQueryMTPV2PubSignals) GetObjMap() map[string]interface{}

GetObjMap returns struct field as a map

func (*AtomicQueryMTPV2PubSignals) PubSignalsUnmarshal

func (ao *AtomicQueryMTPV2PubSignals) PubSignalsUnmarshal(data []byte) error

PubSignalsUnmarshal unmarshal credentialAtomicQueryMTP.circom public signals array to AtomicQueryMTPPubSignals

type AtomicQuerySigInputs

type AtomicQuerySigInputs struct {
	BaseConfig

	// auth
	ID        *core.ID
	AuthClaim ClaimWithMTPProof
	Challenge *big.Int
	Signature *babyjub.Signature

	Claim ClaimWithSigProof // issuerClaim

	Query

	CurrentTimeStamp int64
}

AtomicQuerySigInputs ZK private inputs for credentialAtomicQuerySig.circom Deprecated: use AtomicQuerySigV2Inputs instead

func (AtomicQuerySigInputs) InputsMarshal

func (a AtomicQuerySigInputs) InputsMarshal() ([]byte, error)

InputsMarshal returns Circom private inputs for credentialAtomicQuerySig.circom

type AtomicQuerySigPubSignals

type AtomicQuerySigPubSignals struct {
	BaseConfig
	UserID                 *core.ID         `json:"userID"`
	UserState              *merkletree.Hash `json:"userState"`
	Challenge              *big.Int         `json:"challenge"`
	ClaimSchema            core.SchemaHash  `json:"claimSchema"`
	IssuerID               *core.ID         `json:"issuerID"`
	IssuerAuthState        *merkletree.Hash `json:"issuerAuthState"`
	IssuerClaimNonRevState *merkletree.Hash `json:"issuerClaimNonRevState"`
	SlotIndex              int              `json:"slotIndex"`
	Values                 []*big.Int       `json:"values"`
	Operator               int              `json:"operator"`
	Timestamp              int64            `json:"timestamp"`
}

AtomicQuerySigPubSignals public inputs Deprecated: use AtomicQuerySigV2PubSignals instead

func (AtomicQuerySigPubSignals) GetObjMap

func (ao AtomicQuerySigPubSignals) GetObjMap() map[string]interface{}

GetObjMap returns struct field as a map

func (*AtomicQuerySigPubSignals) PubSignalsUnmarshal

func (ao *AtomicQuerySigPubSignals) PubSignalsUnmarshal(data []byte) error

PubSignalsUnmarshal unmarshal credentialAtomicQuerySig.circom public signals

type AtomicQuerySigV2Inputs

type AtomicQuerySigV2Inputs struct {
	BaseConfig

	RequestID *big.Int

	// auth
	ID                       *core.ID
	ProfileNonce             *big.Int
	ClaimSubjectProfileNonce *big.Int

	Claim                    ClaimWithSigProof // issuerClaim
	SkipClaimRevocationCheck bool

	// query
	Query Query

	CurrentTimeStamp int64
}

AtomicQuerySigInputs ZK private inputs for credentialAtomicQuerySig.circom

func (AtomicQuerySigV2Inputs) InputsMarshal

func (a AtomicQuerySigV2Inputs) InputsMarshal() ([]byte, error)

InputsMarshal returns Circom private inputs for credentialAtomicQuerySig.circom

func (AtomicQuerySigV2Inputs) Validate

func (a AtomicQuerySigV2Inputs) Validate() error

type AtomicQuerySigV2OnChainInputs

type AtomicQuerySigV2OnChainInputs struct {
	BaseConfig

	RequestID *big.Int

	// auth
	ID                       *core.ID
	ProfileNonce             *big.Int
	ClaimSubjectProfileNonce *big.Int

	Claim                    ClaimWithSigProof // issuerClaim
	SkipClaimRevocationCheck bool

	AuthClaim *core.Claim `json:"authClaim"`

	AuthClaimIncMtp    *merkletree.Proof `json:"authClaimIncMtp"`
	AuthClaimNonRevMtp *merkletree.Proof `json:"authClaimNonRevMtp"`
	TreeState          TreeState         `json:"treeState"`

	GISTProof GISTProof `json:"gistProof"`

	Signature *babyjub.Signature `json:"signature"`
	Challenge *big.Int           `json:"challenge"`

	// query
	Query Query

	CurrentTimeStamp int64
}

AtomicQuerySigV2OnChainInputs ZK private inputs for credentialAtomicQuerySig.circom

func (AtomicQuerySigV2OnChainInputs) InputsMarshal

func (a AtomicQuerySigV2OnChainInputs) InputsMarshal() ([]byte, error)

InputsMarshal returns Circom private inputs for credentialAtomicQuerySig.circom

func (AtomicQuerySigV2OnChainInputs) Validate

func (a AtomicQuerySigV2OnChainInputs) Validate() error

type AtomicQuerySigV2OnChainPubSignals

type AtomicQuerySigV2OnChainPubSignals struct {
	BaseConfig
	RequestID              *big.Int         `json:"requestID"`
	UserID                 *core.ID         `json:"userID"`
	IssuerID               *core.ID         `json:"issuerID"`
	IssuerAuthState        *merkletree.Hash `json:"issuerAuthState"`
	IssuerClaimNonRevState *merkletree.Hash `json:"issuerClaimNonRevState"`
	Timestamp              int64            `json:"timestamp"`
	Merklized              int              `json:"merklized"`
	IsRevocationChecked    int              `json:"isRevocationChecked"` // 0 revocation not check, // 1 for check revocation
	QueryHash              *big.Int         `json:"circuitQueryHash"`
	Challenge              *big.Int         `json:"challenge"`
	GlobalRoot             *merkletree.Hash `json:"gistRoot"`
}

AtomicQuerySigV2OnChainPubSignals public inputs

func (AtomicQuerySigV2OnChainPubSignals) GetObjMap

func (ao AtomicQuerySigV2OnChainPubSignals) GetObjMap() map[string]interface{}

GetObjMap returns struct field as a map

func (*AtomicQuerySigV2OnChainPubSignals) PubSignalsUnmarshal

func (ao *AtomicQuerySigV2OnChainPubSignals) PubSignalsUnmarshal(data []byte) error

PubSignalsUnmarshal unmarshal credentialAtomicQuerySig.circom public signals

type AtomicQuerySigV2PubSignals

type AtomicQuerySigV2PubSignals struct {
	BaseConfig
	RequestID              *big.Int         `json:"requestID"`
	UserID                 *core.ID         `json:"userID"`
	IssuerID               *core.ID         `json:"issuerID"`
	IssuerAuthState        *merkletree.Hash `json:"issuerAuthState"`
	IssuerClaimNonRevState *merkletree.Hash `json:"issuerClaimNonRevState"`
	ClaimSchema            core.SchemaHash  `json:"claimSchema"`
	SlotIndex              int              `json:"slotIndex"`
	Operator               int              `json:"operator"`
	Value                  []*big.Int       `json:"value"`
	Timestamp              int64            `json:"timestamp"`
	Merklized              int              `json:"merklized"`
	ClaimPathKey           *big.Int         `json:"claimPathKey"`
	ClaimPathNotExists     int              `json:"claimPathNotExists"`  // 0 for inclusion, 1 for non-inclusion
	IsRevocationChecked    int              `json:"isRevocationChecked"` // 0 revocation not check, // 1 for check revocation
}

AtomicQuerySigV2PubSignals public inputs

func (AtomicQuerySigV2PubSignals) GetObjMap

func (ao AtomicQuerySigV2PubSignals) GetObjMap() map[string]interface{}

GetObjMap returns struct field as a map

func (*AtomicQuerySigV2PubSignals) PubSignalsUnmarshal

func (ao *AtomicQuerySigV2PubSignals) PubSignalsUnmarshal(data []byte) error

PubSignalsUnmarshal unmarshal credentialAtomicQuerySig.circom public signals

type AtomicQueryV3Inputs added in v2.0.1

type AtomicQueryV3Inputs struct {
	BaseConfig

	RequestID *big.Int

	// auth
	ID                       *core.ID
	ProfileNonce             *big.Int
	ClaimSubjectProfileNonce *big.Int

	Claim                    ClaimWithSigAndMTPProof
	SkipClaimRevocationCheck bool

	// query
	Query Query

	CurrentTimeStamp int64

	ProofType ProofType

	LinkNonce *big.Int

	VerifierID *core.ID

	NullifierSessionID *big.Int
}

AtomicQueryV3Inputs ZK private inputs for credentialAtomicQuerySig.circom

func (AtomicQueryV3Inputs) InputsMarshal added in v2.0.1

func (a AtomicQueryV3Inputs) InputsMarshal() ([]byte, error)

InputsMarshal returns Circom private inputs for credentialAtomicQueryV3.circom

func (AtomicQueryV3Inputs) Validate added in v2.0.1

func (a AtomicQueryV3Inputs) Validate() error

type AtomicQueryV3OnChainInputs added in v2.0.1

type AtomicQueryV3OnChainInputs struct {
	BaseConfig

	RequestID *big.Int

	ID                       *core.ID
	ProfileNonce             *big.Int
	ClaimSubjectProfileNonce *big.Int

	Claim                    ClaimWithSigAndMTPProof
	SkipClaimRevocationCheck bool

	AuthClaim *core.Claim `json:"authClaim"`

	AuthClaimIncMtp    *merkletree.Proof `json:"authClaimIncMtp"`
	AuthClaimNonRevMtp *merkletree.Proof `json:"authClaimNonRevMtp"`
	TreeState          TreeState         `json:"treeState"`

	GISTProof GISTProof `json:"gistProof"`

	Signature *babyjub.Signature `json:"signature"`
	Challenge *big.Int           `json:"challenge"`

	// query
	Query Query

	CurrentTimeStamp int64

	ProofType ProofType

	LinkNonce *big.Int

	VerifierID *core.ID

	NullifierSessionID *big.Int

	IsBJJAuthEnabled int
}

AtomicQueryV3OnChainInputs ZK private inputs for credentialAtomicQueryV3OnChain.circom

func (AtomicQueryV3OnChainInputs) InputsMarshal added in v2.0.1

func (a AtomicQueryV3OnChainInputs) InputsMarshal() ([]byte, error)

InputsMarshal returns Circom private inputs for credentialAtomicQueryV3OnChain.circom

func (AtomicQueryV3OnChainInputs) Validate added in v2.0.1

func (a AtomicQueryV3OnChainInputs) Validate() error

type AtomicQueryV3OnChainPubSignals added in v2.0.1

type AtomicQueryV3OnChainPubSignals struct {
	BaseConfig
	RequestID              *big.Int         `json:"requestID"`
	UserID                 *core.ID         `json:"userID"`
	IssuerID               *core.ID         `json:"issuerID"`
	IssuerState            *merkletree.Hash `json:"issuerState"`
	IssuerClaimNonRevState *merkletree.Hash `json:"issuerClaimNonRevState"`
	Timestamp              int64            `json:"timestamp"`
	QueryHash              *big.Int         `json:"circuitQueryHash"`
	Challenge              *big.Int         `json:"challenge"`
	GlobalRoot             *merkletree.Hash `json:"gistRoot"`
	ProofType              int              `json:"proofType"`
	LinkID                 *big.Int         `json:"linkID"`
	Nullifier              *big.Int         `json:"nullifier"`
	OperatorOutput         *big.Int         `json:"operatorOutput"`
	IsBJJAuthEnabled       int              `json:"isBJJAuthEnabled"`
}

AtomicQueryV3OnChainPubSignals public inputs

func (AtomicQueryV3OnChainPubSignals) GetObjMap added in v2.0.1

func (ao AtomicQueryV3OnChainPubSignals) GetObjMap() map[string]interface{}

GetObjMap returns struct field as a map

func (*AtomicQueryV3OnChainPubSignals) PubSignalsUnmarshal added in v2.0.1

func (ao *AtomicQueryV3OnChainPubSignals) PubSignalsUnmarshal(data []byte) error

PubSignalsUnmarshal unmarshal credentialAtomicQueryV3OnChain.circom public signals

type AtomicQueryV3PubSignals added in v2.0.1

type AtomicQueryV3PubSignals struct {
	BaseConfig
	RequestID              *big.Int         `json:"requestID"`
	UserID                 *core.ID         `json:"userID"`
	IssuerID               *core.ID         `json:"issuerID"`
	IssuerState            *merkletree.Hash `json:"issuerState"`
	IssuerClaimNonRevState *merkletree.Hash `json:"issuerClaimNonRevState"`
	ClaimSchema            core.SchemaHash  `json:"claimSchema"`
	SlotIndex              int              `json:"slotIndex"`
	Operator               int              `json:"operator"`
	Value                  []*big.Int       `json:"value"`
	Timestamp              int64            `json:"timestamp"`
	Merklized              int              `json:"merklized"`
	ClaimPathKey           *big.Int         `json:"claimPathKey"`
	IsRevocationChecked    int              `json:"isRevocationChecked"` // 0 revocation not check, // 1 for check revocation
	ProofType              int              `json:"proofType"`
	LinkID                 *big.Int         `json:"linkID"`
	Nullifier              *big.Int         `json:"nullifier"`
	OperatorOutput         *big.Int         `json:"operatorOutput"`
	VerifierID             *core.ID         `json:"verifierID"`
	NullifierSessionID     *big.Int         `json:"nullifierSessionID"`
	ActualValueArraySize   int              `json:"valueArraySize"`
}

AtomicQueryV3PubSignals public inputs

func (AtomicQueryV3PubSignals) GetObjMap added in v2.0.1

func (ao AtomicQueryV3PubSignals) GetObjMap() map[string]interface{}

GetObjMap returns struct field as a map

func (*AtomicQueryV3PubSignals) PubSignalsUnmarshal added in v2.0.1

func (ao *AtomicQueryV3PubSignals) PubSignalsUnmarshal(data []byte) error

PubSignalsUnmarshal unmarshal credentialAtomicQueryV3.circom public signals

type AuthInputs

type AuthInputs struct {
	BaseConfig

	ID *core.ID

	AuthClaim ClaimWithMTPProof

	Signature *babyjub.Signature
	Challenge *big.Int
}

AuthInputs type represent auth.circom private inputs Deprecated: use AuthV2Inputs instead

func (AuthInputs) InputsMarshal

func (a AuthInputs) InputsMarshal() ([]byte, error)

InputsMarshal returns Circom private inputs for auth.circom

type AuthPubSignals

type AuthPubSignals struct {
	Challenge *big.Int         `json:"challenge"`
	UserState *merkletree.Hash `json:"userState"`
	UserID    *core.ID         `json:"userID"`
}

AuthPubSignals auth.circom public signals Deprecated: use AuthV2PubSignals instead

func (AuthPubSignals) GetObjMap

func (a AuthPubSignals) GetObjMap() map[string]interface{}

GetObjMap returns AuthPubSignals as a map

func (*AuthPubSignals) PubSignalsUnmarshal

func (a *AuthPubSignals) PubSignalsUnmarshal(data []byte) error

PubSignalsUnmarshal unmarshal auth.circom public inputs to AuthPubSignals

type AuthV2Inputs

type AuthV2Inputs struct {
	BaseConfig

	GenesisID    *core.ID `json:"genesisID"`
	ProfileNonce *big.Int `json:"profileNonce"`

	AuthClaim *core.Claim `json:"authClaim"`

	AuthClaimIncMtp    *merkletree.Proof `json:"authClaimIncMtp"`
	AuthClaimNonRevMtp *merkletree.Proof `json:"authClaimNonRevMtp"`
	TreeState          TreeState         `json:"treeState"`

	GISTProof GISTProof `json:"gistProof"`

	Signature *babyjub.Signature `json:"signature"`
	Challenge *big.Int           `json:"challenge"`
}

AuthV2Inputs type represent authV2.circom inputs

func (AuthV2Inputs) InputsMarshal

func (a AuthV2Inputs) InputsMarshal() ([]byte, error)

InputsMarshal returns Circom private inputs for auth.circom

func (AuthV2Inputs) MarshalJSON

func (a AuthV2Inputs) MarshalJSON() ([]byte, error)

func (*AuthV2Inputs) UnmarshalJSON

func (a *AuthV2Inputs) UnmarshalJSON(in []byte) error

func (AuthV2Inputs) Validate

func (a AuthV2Inputs) Validate() error

type AuthV2PubSignals

type AuthV2PubSignals struct {
	UserID    *core.ID         `json:"userID"`
	Challenge *big.Int         `json:"challenge"`
	GISTRoot  *merkletree.Hash `json:"GISTRoot"`
}

AuthV2PubSignals auth.circom public signals

func (AuthV2PubSignals) GetObjMap

func (a AuthV2PubSignals) GetObjMap() map[string]interface{}

GetObjMap returns AuthPubSignals as a map

func (*AuthV2PubSignals) PubSignalsUnmarshal

func (a *AuthV2PubSignals) PubSignalsUnmarshal(data []byte) error

PubSignalsUnmarshal unmarshal auth.circom public inputs to AuthPubSignals

type BJJSignatureProof

type BJJSignatureProof struct {
	// Signature Signing the claim with the private key of the issuer associated with the issuerAuthClaim
	Signature       *babyjub.Signature `json:"signature"`
	IssuerAuthClaim *core.Claim        `json:"issuerAuthClaim"` // issuer AuthClaim
	// IssuerAuthIncProof proof of inclusion of issuer AuthClaim to
	// the issuer claims tree
	IssuerAuthIncProof MTProof `json:"issuerAuthIncProof"`
	// IssuerAuthNonRevProof proof of non revocation of issuer
	// AuthClaim in the issuer the latest state
	IssuerAuthNonRevProof MTProof `json:"issuerAuthNonRevProof"`
}

BJJSignatureProof is a proof of issuer AuthClaim signature over a claim

type BaseConfig

type BaseConfig struct {
	MTLevel        int // Max levels of MT
	ValueArraySize int // Size if value array in identity circuits
	MTLevelOnChain int // Max levels of MT on chain
	MTLevelClaim   int // Max level of JSONLD claim
}

BaseConfig base circuit's config, provides default configuration for default circuits

func (BaseConfig) GetMTLevel

func (c BaseConfig) GetMTLevel() int

GetMTLevel max circuit MT levels

func (BaseConfig) GetMTLevelOnChain

func (c BaseConfig) GetMTLevelOnChain() int

GetMTLevel max circuit MT levels on chain

func (BaseConfig) GetMTLevelsClaim

func (c BaseConfig) GetMTLevelsClaim() int

GetMTLevelsClaim max jsonld Claim levels

func (BaseConfig) GetValueArrSize

func (c BaseConfig) GetValueArrSize() int

GetValueArrSize return size of circuits value array size

type CircuitID

type CircuitID string

CircuitID is alias for circuit identifier

const (
	// AuthCircuitID is a type that must be used for auth.circom
	AuthCircuitID CircuitID = "auth"
	// AuthCircuitID is a type that must be used for authV2.circom
	AuthV2CircuitID CircuitID = "authV2"
	// StateTransitionCircuitID is a type that must be used for stateTransition.circom
	StateTransitionCircuitID CircuitID = "stateTransition"
	// AtomicQueryMTPCircuitID is a type for credentialAtomicQueryMTP.circom
	AtomicQueryMTPCircuitID CircuitID = "credentialAtomicQueryMTP"
	// AtomicQueryMTPV2CircuitID is a type for credentialAtomicQueryMTPV2.circom
	AtomicQueryMTPV2CircuitID CircuitID = "credentialAtomicQueryMTPV2"
	// AtomicQueryV3CircuitID is a type for credentialAtomicQueryV3.circom
	AtomicQueryV3CircuitID CircuitID = "credentialAtomicQueryV3-beta.1"
	// AtomicQueryMTPV2OnChainCircuitID is a type for credentialAtomicQueryMTPV2OnChain.circom
	AtomicQueryMTPV2OnChainCircuitID CircuitID = "credentialAtomicQueryMTPV2OnChain"
	// AtomicQuerySigCircuitID is a type for credentialAttrQuerySig.circom
	AtomicQuerySigCircuitID CircuitID = "credentialAtomicQuerySig"
	// AtomicQuerySigV2CircuitID is a type for credentialAttrQuerySigV2.circom
	AtomicQuerySigV2CircuitID CircuitID = "credentialAtomicQuerySigV2"
	// AtomicQuerySigV2OnChainCircuitID is a type for credentialAttrQuerySigV2OnChain.circom
	AtomicQuerySigV2OnChainCircuitID CircuitID = "credentialAtomicQuerySigV2OnChain"
	// AtomicQueryV3OnChainCircuitID is a type for credentialAtomicQueryV3OnChain.circom
	AtomicQueryV3OnChainCircuitID CircuitID = "credentialAtomicQueryV3OnChain-beta.1"
	// JsonLDAtomicQueryMTPCircuitID is a type for credentialJsonLDAtomicQueryMTP.circom
	JsonLDAtomicQueryMTPCircuitID CircuitID = "credentialJsonLDAtomicQueryMTP"
	// SybilMTPCircuitID is a type for sybilMTP.circom
	SybilMTPCircuitID CircuitID = "sybilCredentialAtomicMTP"
	// SybilSigCircuitID is a type for sybilSig.circom
	SybilSigCircuitID CircuitID = "sybilCredentialAtomicSig"
	// LinkedMultiQuery10CircuitID is a type for linkedMultiQuery10.circom
	LinkedMultiQuery10CircuitID CircuitID = "linkedMultiQuery10-beta.1"
)

type ClaimWithMTPProof

type ClaimWithMTPProof struct {
	IssuerID    *core.ID    `json:"issuerId"`
	Claim       *core.Claim `json:"claim"`
	IncProof    MTProof     `json:"incProof"`    // proof of inclusion `Claim` to the issuer claims tree
	NonRevProof MTProof     `json:"nonRevProof"` // proof of non revocation of the `Claim` in the issuer revocation tree
}

type ClaimWithSigAndMTPProof added in v2.0.1

type ClaimWithSigAndMTPProof struct {
	IssuerID       *core.ID           `json:"issuerID"`
	Claim          *core.Claim        `json:"claim"`
	NonRevProof    MTProof            `json:"nonRevProof"` // Claim non revocation proof
	SignatureProof *BJJSignatureProof `json:"signatureProof"`
	IncProof       *MTProof           `json:"incProof"` // proof of inclusion `Claim` to the issuer claims tree
}

type ClaimWithSigProof

type ClaimWithSigProof struct {
	IssuerID       *core.ID          `json:"issuerID"`
	Claim          *core.Claim       `json:"claim"`
	NonRevProof    MTProof           `json:"nonRevProof"` // Claim non revocation proof
	SignatureProof BJJSignatureProof `json:"signatureProof"`
}

type Comparer

type Comparer interface {
	Compare(int) (bool, error)
}

Comparer value.

func FactoryComparer

func FactoryComparer(x *big.Int, y []*big.Int, t int) (Comparer, error)

FactoryComparer depends on input data will return right comparer.

type Data

type Data struct {
	Input  InputsMarshaller // input values type
	Output PubSignals       // output values type
}

Data circuit type

func GetCircuit

func GetCircuit(id CircuitID) (*Data, error)

GetCircuit return circuit Data

type GISTProof

type GISTProof struct {
	Root  *merkletree.Hash  `json:"root"`  // GIST root
	Proof *merkletree.Proof `json:"proof"` // proof of inclusion or non inclusion of the identity to the GIST
}

GISTProof global identity state tree proof represents the state of the global identities tree published on the blockchain

type InputsMarshaller

type InputsMarshaller interface {
	InputsMarshal() ([]byte, error)
}

InputsMarshaller interface implemented by types that can marshal circuit `input` structures

type KeyLoader

type KeyLoader interface {
	Load() ([]byte, error)
}

KeyLoader interface, if key should be fetched from file system, CDN, IPFS etc, this interface may be implemented for key loading from a specific place

type LinkedMultiQueryInputs added in v2.1.0

type LinkedMultiQueryInputs struct {
	BaseConfig
	LinkNonce *big.Int
	Claim     *core.Claim
	Query     []*Query
}

LinkedMultiQueryInputs type represent linkedMultiQuery10.circom inputs

func (LinkedMultiQueryInputs) InputsMarshal added in v2.1.0

func (l LinkedMultiQueryInputs) InputsMarshal() ([]byte, error)

InputsMarshal returns Circom private inputs for linkedMultiQuery10.circom

func (LinkedMultiQueryInputs) Validate added in v2.2.0

func (l LinkedMultiQueryInputs) Validate() error

type LinkedMultiQueryPubSignals added in v2.1.0

type LinkedMultiQueryPubSignals struct {
	LinkID           *big.Int   `json:"linkID"`
	Merklized        int        `json:"merklized"`
	OperatorOutput   []*big.Int `json:"operatorOutput"`
	CircuitQueryHash []*big.Int `json:"circuitQueryHash"`
}

LinkedMultiQueryPubSignals linkedMultiQuery10.circom public signals

func (LinkedMultiQueryPubSignals) GetObjMap added in v2.1.0

func (l LinkedMultiQueryPubSignals) GetObjMap() map[string]interface{}

GetObjMap returns LinkedMultiQueryPubSignals as a map

func (*LinkedMultiQueryPubSignals) PubSignalsUnmarshal added in v2.1.0

func (lo *LinkedMultiQueryPubSignals) PubSignalsUnmarshal(data []byte) error

PubSignalsUnmarshal unmarshal linkedMultiQuery10.circom public inputs to LinkedMultiQueryPubSignals

type MTProof

type MTProof struct {
	Proof     *merkletree.Proof `json:"proof"`     // Proof of inclusion to the Merkle Tree
	TreeState TreeState         `json:"treeState"` // Identity state
}

type NodeAuxValue

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

func GetNodeAuxValue

func GetNodeAuxValue(p *merkletree.Proof) NodeAuxValue

type ProofType added in v2.0.1

type ProofType string
const (
	BJJSignatureProofType          ProofType = "BJJSignature2021"
	Iden3SparseMerkleTreeProofType ProofType = "Iden3SparseMerkleTreeProof"
)

type PubSignals

type PubSignals interface {
	PubSignalsUnmarshaller
	PubSignalsMapper
}

PubSignals interface implemented by types that can be registered in circuit registry

type PubSignalsMapper

type PubSignalsMapper interface {
	GetObjMap() map[string]interface{}
}

PubSignalsMapper interface implemented by types that can unmarshal circuit `output` to map

type PubSignalsUnmarshaller

type PubSignalsUnmarshaller interface {
	PubSignalsUnmarshal(data []byte) error
}

PubSignalsUnmarshaller interface implemented by types that can unmarshal circuit `output` structures

type Query

type Query struct {
	Operator   int
	Values     []*big.Int
	SlotIndex  int
	ValueProof *ValueProof
}

Query represents basic request to claim field with MTP and without

func (Query) ValidateValueArraySize added in v2.1.0

func (q Query) ValidateValueArraySize(maxArrSize int) error

Validate value size for operator

type Scalar

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

Scalar uses for compare two scalar value.

func NewScalar

func NewScalar(x, y *big.Int) *Scalar

NewScalar create `Scalar` comparer.

func (*Scalar) Compare

func (s *Scalar) Compare(t int) (bool, error)

Compare x with y by target QueryOperators. Scalar compare support: $eq, $lt, $gt, $ne, $lte, $gte type.

type StateTransitionInputs

type StateTransitionInputs struct {
	BaseConfig

	ID *core.ID

	OldTreeState      TreeState
	NewTreeState      TreeState
	IsOldStateGenesis bool

	AuthClaim               *core.Claim       `json:"claim"`
	AuthClaimIncMtp         *merkletree.Proof `json:"authClaimIncMtp"`
	AuthClaimNonRevMtp      *merkletree.Proof `json:"authClaimNonRevMtp"`
	AuthClaimNewStateIncMtp *merkletree.Proof `json:"authClaimNewStateIncMtp"`

	Signature *babyjub.Signature
}

StateTransitionInputs ZK private inputs for stateTransition.circom

func (StateTransitionInputs) InputsMarshal

func (c StateTransitionInputs) InputsMarshal() ([]byte, error)

InputsMarshal returns Circom private inputs for stateTransition.circom

type StateTransitionPubSignals

type StateTransitionPubSignals struct {
	UserID            *core.ID         `json:"userID"`
	OldUserState      *merkletree.Hash `json:"oldUserState"`
	NewUserState      *merkletree.Hash `json:"newUserState"`
	IsOldStateGenesis bool             `json:"isOldStateGenesis"`
}

StateTransitionPubSignals stateTransition.circom public inputs

func (StateTransitionPubSignals) GetObjMap

func (s StateTransitionPubSignals) GetObjMap() map[string]interface{}

GetObjMap returns struct field as a map

func (*StateTransitionPubSignals) PubSignalsUnmarshal

func (s *StateTransitionPubSignals) PubSignalsUnmarshal(data []byte) error

PubSignalsUnmarshal unmarshal stateTransition.circom public signals

type SybilAtomicMTPInputs deprecated

type SybilAtomicMTPInputs struct {
	BaseConfig

	ID                       *core.ID
	ProfileNonce             *big.Int
	ClaimSubjectProfileNonce *big.Int

	IssuerClaim          ClaimWithMTPProof
	StateCommitmentClaim ClaimWithMTPProof

	GISTProof GISTProof
	CRS       *big.Int

	RequestID *big.Int
	Timestamp int64
}

Deprecated: trusted setup is not done for that circuits. In future releases

new circuit with sybil support will be added.

func (SybilAtomicMTPInputs) InputsMarshal

func (s SybilAtomicMTPInputs) InputsMarshal() ([]byte, error)

func (SybilAtomicMTPInputs) Validate

func (s SybilAtomicMTPInputs) Validate() error

type SybilAtomicMTPPubSignals deprecated

type SybilAtomicMTPPubSignals struct {
	BaseConfig

	SybilID *big.Int `json:"sybilID"`
	UserID  *core.ID `json:"userID"`

	RequestID *big.Int `json:"requestID"`
	IssuerID  *core.ID `json:"issuerID"`
	Timestamp int64    `json:"timestamp"`

	IssuerClaimIdenState   *merkletree.Hash `json:"issuerClaimIdenState"`
	IssuerClaimNonRevState *merkletree.Hash `json:"issuerClaimNonRevState"`
	ClaimSchema            core.SchemaHash  `json:"claimSchema"`

	CRS *big.Int `json:"crs"`

	GISTRoot *merkletree.Hash `json:"gistRoot"`
}

Deprecated: trusted setup is not done for that circuits. In future releases

new circuit with sybil support will be added.

func (SybilAtomicMTPPubSignals) GetObjMap

func (s SybilAtomicMTPPubSignals) GetObjMap() map[string]interface{}

func (*SybilAtomicMTPPubSignals) PubSignalsUnmarshal

func (s *SybilAtomicMTPPubSignals) PubSignalsUnmarshal(data []byte) error

type SybilAtomicSigInputs deprecated

type SybilAtomicSigInputs struct {
	BaseConfig

	ID                       *core.ID
	ProfileNonce             *big.Int
	ClaimSubjectProfileNonce *big.Int

	IssuerClaim          ClaimWithSigProof
	StateCommitmentClaim ClaimWithMTPProof

	GISTProof GISTProof
	CRS       *big.Int

	RequestID *big.Int
	Timestamp int64
}

Deprecated: trusted setup is not done for that circuits. In future released

new circuit with sybil support will be added.

func (SybilAtomicSigInputs) InputsMarshal

func (s SybilAtomicSigInputs) InputsMarshal() ([]byte, error)

func (SybilAtomicSigInputs) Validate

func (s SybilAtomicSigInputs) Validate() error

type SybilAtomicSigPubSignals deprecated

type SybilAtomicSigPubSignals struct {
	BaseConfig

	SybilID *big.Int `json:"sybilID"`
	UserID  *core.ID `json:"userID"`

	RequestID *big.Int `json:"requestID"`
	IssuerID  *core.ID `json:"issuerID"`
	Timestamp int64    `json:"timestamp"`

	IssuerClaimNonRevState *merkletree.Hash `json:"issuerClaimNonRevState"`

	ClaimSchema core.SchemaHash `json:"claimSchema"`

	CRS *big.Int `json:"crs"`

	GISTRoot *merkletree.Hash `json:"gistRoot"`

	IssuerAuthState *merkletree.Hash `json:"issuerAuthState"`
}

Deprecated: trusted setup is not done for that circuits. In future released

new circuit with sybil support will be added.

func (SybilAtomicSigPubSignals) GetObjMap

func (s SybilAtomicSigPubSignals) GetObjMap() map[string]interface{}

func (*SybilAtomicSigPubSignals) PubSignalsUnmarshal

func (s *SybilAtomicSigPubSignals) PubSignalsUnmarshal(data []byte) error

type TreeState

type TreeState struct {
	State          *merkletree.Hash `json:"state"`          // identity state
	ClaimsRoot     *merkletree.Hash `json:"claimsRoot"`     // claims tree root
	RevocationRoot *merkletree.Hash `json:"revocationRoot"` // revocation tree root
	RootOfRoots    *merkletree.Hash `json:"rootOfRoots"`    // root of roots tree root
}

TreeState represents the identity state

type ValueProof

type ValueProof struct {
	Path  *big.Int
	Value *big.Int
	MTP   *merkletree.Proof
}

ValueProof represents a Merkle Proof for a value stored as MT

type Vector

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

Vector uses for find/not find x scalar type in y vector type.

func NewVector

func NewVector(x *big.Int, y []*big.Int) *Vector

NewVector create Vector.

func (*Vector) Compare

func (v *Vector) Compare(t int) (bool, error)

Compare find/not find x in y by type. Vector compare support: $in, $nin, $between

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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