Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement StateInfoPubSignals interface #89

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions authV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ type AuthV2PubSignals struct {
GISTRoot *merkletree.Hash `json:"GISTRoot"`
}

func (ao *AuthV2PubSignals) GetStatesInfo() StatesInfo {
return StatesInfo{
States: []States{},
Gists: []Gists{
{
ID: ao.UserID,
Root: ao.GISTRoot,
},
},
}
}

// PubSignalsUnmarshal unmarshal auth.circom public inputs to AuthPubSignals
func (a *AuthV2PubSignals) PubSignalsUnmarshal(data []byte) error {
var sVals []string
Expand Down
29 changes: 27 additions & 2 deletions circuits.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"reflect"
"sync"

core "github.com/iden3/go-iden3-core/v2"
"github.com/iden3/go-merkletree-sql/v2"
"github.com/pkg/errors"
)

Expand All @@ -13,7 +15,7 @@ type CircuitID string
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 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"
Expand Down Expand Up @@ -158,7 +160,7 @@ func (c BaseConfig) GetValueArrSize() int {
return c.ValueArraySize
}

// GetMTLevel max circuit MT levels on chain
// GetMTLevelOnChain max circuit MT levels on chain
func (c BaseConfig) GetMTLevelOnChain() int {
if c.MTLevelOnChain == 0 {
return defaultMTLevelsOnChain
Expand Down Expand Up @@ -196,6 +198,29 @@ type PubSignals interface {
PubSignalsMapper
}

// StateInfoPubSignals interface implemented by types that can return states info
type StateInfoPubSignals interface {
GetStatesInfo() StatesInfo
}

// StatesInfo struct. A collection of states and gists
type StatesInfo struct {
States []States
Gists []Gists
}

// States information
type States struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@x1m3 @vmidyllic
Why it is plural States and Gists?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, it should be State/ Gist or just anonymus

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree. Changed

ID *core.ID
State *merkletree.Hash
}

// Gists information
type Gists struct {
ID *core.ID
Root *merkletree.Hash
}

// 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 KeyLoader interface {
Expand Down
2 changes: 1 addition & 1 deletion credentialAtomicQueryMTPV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (a AtomicQueryMTPV2Inputs) InputsMarshal() ([]byte, error) {
return json.Marshal(s)
}

// AtomicQueryMTPPubSignals public signals
// AtomicQueryMTPV2PubSignals public signals
type AtomicQueryMTPV2PubSignals struct {
BaseConfig
RequestID *big.Int `json:"requestID"`
Expand Down
21 changes: 21 additions & 0 deletions credentialAtomicQueryMTPV2OnChain.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,27 @@ type AtomicQueryMTPV2OnChainPubSignals struct {
GlobalRoot *merkletree.Hash `json:"gistRoot"`
}

func (ao *AtomicQueryMTPV2OnChainPubSignals) GetStatesInfo() StatesInfo {
return StatesInfo{
States: []States{
{
ID: ao.IssuerID,
State: ao.IssuerClaimIdenState,
},
{
ID: ao.IssuerID,
State: ao.IssuerClaimNonRevState,
},
},
Gists: []Gists{
{
ID: ao.UserID,
Root: ao.GlobalRoot,
},
},
}
}

// PubSignalsUnmarshal unmarshal credentialAtomicQueryMTPV2OnChain.circom public signals array to AtomicQueryMTPPubSignals
func (ao *AtomicQueryMTPV2OnChainPubSignals) PubSignalsUnmarshal(data []byte) error {

Expand Down
21 changes: 21 additions & 0 deletions credentialAtomicQuerySigV2OnChain.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,27 @@ type AtomicQuerySigV2OnChainPubSignals struct {
GlobalRoot *merkletree.Hash `json:"gistRoot"`
}

func (ao *AtomicQuerySigV2OnChainPubSignals) GetStatesInfo() StatesInfo {
return StatesInfo{
States: []States{
{
ID: ao.IssuerID,
State: ao.IssuerAuthState,
},
{
ID: ao.IssuerID,
State: ao.IssuerClaimNonRevState,
},
},
Gists: []Gists{
{
ID: ao.UserID,
Root: ao.GlobalRoot,
},
},
}
}

// PubSignalsUnmarshal unmarshal credentialAtomicQuerySig.circom public signals
func (ao *AtomicQuerySigV2OnChainPubSignals) PubSignalsUnmarshal(data []byte) error {
// expected order:
Expand Down
21 changes: 21 additions & 0 deletions credentialAtomicQueryV3OnChain.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,27 @@ type AtomicQueryV3OnChainPubSignals struct {
IsBJJAuthEnabled int `json:"isBJJAuthEnabled"`
}

func (ao *AtomicQueryV3OnChainPubSignals) GetStatesInfo() StatesInfo {
return StatesInfo{
States: []States{
{
ID: ao.IssuerID,
State: ao.IssuerState,
},
{
ID: ao.IssuerID,
State: ao.IssuerClaimNonRevState,
},
},
Gists: []Gists{
{
ID: ao.UserID,
Root: ao.GlobalRoot,
},
},
}
}

// PubSignalsUnmarshal unmarshal credentialAtomicQueryV3OnChain.circom public signals
func (ao *AtomicQueryV3OnChainPubSignals) PubSignalsUnmarshal(data []byte) error {
// expected order:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/iden3/go-iden3-core/v2 v2.3.1
github.com/iden3/go-iden3-crypto v0.0.17
github.com/iden3/go-merkletree-sql/v2 v2.0.4
github.com/iden3/go-merkletree-sql/v2 v2.0.6
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/iden3/go-iden3-core/v2 v2.3.1 h1:ytQqiclnVAIWyRKR2LF31hfz4DGRBD6nMjiP
github.com/iden3/go-iden3-core/v2 v2.3.1/go.mod h1:8vmG6y8k9VS7iNoxuiKukKbRQFsMyabCc+i8er07zOs=
github.com/iden3/go-iden3-crypto v0.0.17 h1:NdkceRLJo/pI4UpcjVah4lN/a3yzxRUGXqxbWcYh9mY=
github.com/iden3/go-iden3-crypto v0.0.17/go.mod h1:dLpM4vEPJ3nDHzhWFXDjzkn1qHoBeOT/3UEhXsEsP3E=
github.com/iden3/go-merkletree-sql/v2 v2.0.4 h1:Dp089P3YNX1BE8+T1tKQHWTtnk84Y/Kr7ZAGTqwscoY=
github.com/iden3/go-merkletree-sql/v2 v2.0.4/go.mod h1:kRhHKYpui5DUsry5RpveP6IC4XMe6iApdV9VChRYuEk=
github.com/iden3/go-merkletree-sql/v2 v2.0.6 h1:vsVDImnvnHf7Ggr45ptFOXJyWNA/8IwVQO1jzRLUlY8=
github.com/iden3/go-merkletree-sql/v2 v2.0.6/go.mod h1:kRhHKYpui5DUsry5RpveP6IC4XMe6iApdV9VChRYuEk=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
Expand Down
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func PrepareSiblingsStr(siblings []*merkletree.Hash, levels int) []string {
return HashToStr(siblings)
}

// CircomSiblingsFromSiblings returns the full siblings compatible with circom
// CircomSiblings returns the full siblings compatible with circom
func CircomSiblings(proof *merkletree.Proof, levels int) []*merkletree.Hash {
siblings := proof.AllSiblings()
// Add the rest of empty levels to the siblings
Expand Down
Loading