diff --git a/authV2.go b/authV2.go index 5e03426..d36bc7e 100644 --- a/authV2.go +++ b/authV2.go @@ -142,6 +142,18 @@ type AuthV2PubSignals struct { GISTRoot *merkletree.Hash `json:"GISTRoot"` } +func (ao *AuthV2PubSignals) GetStatesInfo() StatesInfo { + return StatesInfo{ + States: []State{}, + Gists: []Gist{ + { + ID: ao.UserID, + Root: ao.GISTRoot, + }, + }, + } +} + // PubSignalsUnmarshal unmarshal auth.circom public inputs to AuthPubSignals func (a *AuthV2PubSignals) PubSignalsUnmarshal(data []byte) error { var sVals []string diff --git a/circuits.go b/circuits.go index 58a2197..488d447 100644 --- a/circuits.go +++ b/circuits.go @@ -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" ) @@ -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" @@ -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 @@ -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 []State + Gists []Gist +} + +// State information +type State struct { + ID *core.ID + State *merkletree.Hash +} + +// Gist information +type Gist 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 { diff --git a/credentialAtomicQueryMTPV2.go b/credentialAtomicQueryMTPV2.go index 1dde053..c8e636e 100644 --- a/credentialAtomicQueryMTPV2.go +++ b/credentialAtomicQueryMTPV2.go @@ -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"` diff --git a/credentialAtomicQueryMTPV2OnChain.go b/credentialAtomicQueryMTPV2OnChain.go index 83d5977..5e74c8a 100644 --- a/credentialAtomicQueryMTPV2OnChain.go +++ b/credentialAtomicQueryMTPV2OnChain.go @@ -267,6 +267,27 @@ type AtomicQueryMTPV2OnChainPubSignals struct { GlobalRoot *merkletree.Hash `json:"gistRoot"` } +func (ao *AtomicQueryMTPV2OnChainPubSignals) GetStatesInfo() StatesInfo { + return StatesInfo{ + States: []State{ + { + ID: ao.IssuerID, + State: ao.IssuerClaimIdenState, + }, + { + ID: ao.IssuerID, + State: ao.IssuerClaimNonRevState, + }, + }, + Gists: []Gist{ + { + ID: ao.UserID, + Root: ao.GlobalRoot, + }, + }, + } +} + // PubSignalsUnmarshal unmarshal credentialAtomicQueryMTPV2OnChain.circom public signals array to AtomicQueryMTPPubSignals func (ao *AtomicQueryMTPV2OnChainPubSignals) PubSignalsUnmarshal(data []byte) error { diff --git a/credentialAtomicQuerySigV2OnChain.go b/credentialAtomicQuerySigV2OnChain.go index f25a16b..a8e53af 100644 --- a/credentialAtomicQuerySigV2OnChain.go +++ b/credentialAtomicQuerySigV2OnChain.go @@ -310,6 +310,27 @@ type AtomicQuerySigV2OnChainPubSignals struct { GlobalRoot *merkletree.Hash `json:"gistRoot"` } +func (ao *AtomicQuerySigV2OnChainPubSignals) GetStatesInfo() StatesInfo { + return StatesInfo{ + States: []State{ + { + ID: ao.IssuerID, + State: ao.IssuerAuthState, + }, + { + ID: ao.IssuerID, + State: ao.IssuerClaimNonRevState, + }, + }, + Gists: []Gist{ + { + ID: ao.UserID, + Root: ao.GlobalRoot, + }, + }, + } +} + // PubSignalsUnmarshal unmarshal credentialAtomicQuerySig.circom public signals func (ao *AtomicQuerySigV2OnChainPubSignals) PubSignalsUnmarshal(data []byte) error { // expected order: diff --git a/credentialAtomicQueryV3OnChain.go b/credentialAtomicQueryV3OnChain.go index ef32c79..8ad3bb2 100644 --- a/credentialAtomicQueryV3OnChain.go +++ b/credentialAtomicQueryV3OnChain.go @@ -464,6 +464,27 @@ type AtomicQueryV3OnChainPubSignals struct { IsBJJAuthEnabled int `json:"isBJJAuthEnabled"` } +func (ao *AtomicQueryV3OnChainPubSignals) GetStatesInfo() StatesInfo { + return StatesInfo{ + States: []State{ + { + ID: ao.IssuerID, + State: ao.IssuerState, + }, + { + ID: ao.IssuerID, + State: ao.IssuerClaimNonRevState, + }, + }, + Gists: []Gist{ + { + ID: ao.UserID, + Root: ao.GlobalRoot, + }, + }, + } +} + // PubSignalsUnmarshal unmarshal credentialAtomicQueryV3OnChain.circom public signals func (ao *AtomicQueryV3OnChainPubSignals) PubSignalsUnmarshal(data []byte) error { // expected order: diff --git a/go.mod b/go.mod index 8f1380c..b956cb7 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index fccfa83..0ce6886 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/utils.go b/utils.go index f65ec7a..44afe50 100644 --- a/utils.go +++ b/utils.go @@ -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