From 0cc95248296e2528c9f6a67a41978b93d0af9082 Mon Sep 17 00:00:00 2001 From: x1m3 Date: Wed, 30 Oct 2024 16:32:51 +0100 Subject: [PATCH 1/2] feat: Implement StateInfoPubSignals interface. --- authV2.go | 12 ++++++++++++ circuits.go | 29 ++++++++++++++++++++++++++-- credentialAtomicQueryMTPV2.go | 2 +- credentialAtomicQueryMTPV2OnChain.go | 21 ++++++++++++++++++++ credentialAtomicQuerySigV2OnChain.go | 21 ++++++++++++++++++++ credentialAtomicQueryV3OnChain.go | 21 ++++++++++++++++++++ go.mod | 2 +- go.sum | 4 ++-- utils.go | 2 +- 9 files changed, 107 insertions(+), 7 deletions(-) diff --git a/authV2.go b/authV2.go index 5e03426..a3e87c2 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: []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 diff --git a/circuits.go b/circuits.go index 58a2197..5bc3c1b 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 []States + Gists []Gists +} + +// States information +type States struct { + 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 { 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..a00ea63 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: []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 { diff --git a/credentialAtomicQuerySigV2OnChain.go b/credentialAtomicQuerySigV2OnChain.go index f25a16b..c23a6e9 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: []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: diff --git a/credentialAtomicQueryV3OnChain.go b/credentialAtomicQueryV3OnChain.go index ef32c79..dbecc1e 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: []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: 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 From 2c17268a79d5bab6ab8f861fcd9b955803809f08 Mon Sep 17 00:00:00 2001 From: x1m3 Date: Tue, 5 Nov 2024 10:11:41 +0100 Subject: [PATCH 2/2] chore: suggestion accepted. States and Signals to be in singular --- authV2.go | 4 ++-- circuits.go | 12 ++++++------ credentialAtomicQueryMTPV2OnChain.go | 4 ++-- credentialAtomicQuerySigV2OnChain.go | 4 ++-- credentialAtomicQueryV3OnChain.go | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/authV2.go b/authV2.go index a3e87c2..d36bc7e 100644 --- a/authV2.go +++ b/authV2.go @@ -144,8 +144,8 @@ type AuthV2PubSignals struct { func (ao *AuthV2PubSignals) GetStatesInfo() StatesInfo { return StatesInfo{ - States: []States{}, - Gists: []Gists{ + States: []State{}, + Gists: []Gist{ { ID: ao.UserID, Root: ao.GISTRoot, diff --git a/circuits.go b/circuits.go index 5bc3c1b..488d447 100644 --- a/circuits.go +++ b/circuits.go @@ -205,18 +205,18 @@ type StateInfoPubSignals interface { // StatesInfo struct. A collection of states and gists type StatesInfo struct { - States []States - Gists []Gists + States []State + Gists []Gist } -// States information -type States struct { +// State information +type State struct { ID *core.ID State *merkletree.Hash } -// Gists information -type Gists struct { +// Gist information +type Gist struct { ID *core.ID Root *merkletree.Hash } diff --git a/credentialAtomicQueryMTPV2OnChain.go b/credentialAtomicQueryMTPV2OnChain.go index a00ea63..5e74c8a 100644 --- a/credentialAtomicQueryMTPV2OnChain.go +++ b/credentialAtomicQueryMTPV2OnChain.go @@ -269,7 +269,7 @@ type AtomicQueryMTPV2OnChainPubSignals struct { func (ao *AtomicQueryMTPV2OnChainPubSignals) GetStatesInfo() StatesInfo { return StatesInfo{ - States: []States{ + States: []State{ { ID: ao.IssuerID, State: ao.IssuerClaimIdenState, @@ -279,7 +279,7 @@ func (ao *AtomicQueryMTPV2OnChainPubSignals) GetStatesInfo() StatesInfo { State: ao.IssuerClaimNonRevState, }, }, - Gists: []Gists{ + Gists: []Gist{ { ID: ao.UserID, Root: ao.GlobalRoot, diff --git a/credentialAtomicQuerySigV2OnChain.go b/credentialAtomicQuerySigV2OnChain.go index c23a6e9..a8e53af 100644 --- a/credentialAtomicQuerySigV2OnChain.go +++ b/credentialAtomicQuerySigV2OnChain.go @@ -312,7 +312,7 @@ type AtomicQuerySigV2OnChainPubSignals struct { func (ao *AtomicQuerySigV2OnChainPubSignals) GetStatesInfo() StatesInfo { return StatesInfo{ - States: []States{ + States: []State{ { ID: ao.IssuerID, State: ao.IssuerAuthState, @@ -322,7 +322,7 @@ func (ao *AtomicQuerySigV2OnChainPubSignals) GetStatesInfo() StatesInfo { State: ao.IssuerClaimNonRevState, }, }, - Gists: []Gists{ + Gists: []Gist{ { ID: ao.UserID, Root: ao.GlobalRoot, diff --git a/credentialAtomicQueryV3OnChain.go b/credentialAtomicQueryV3OnChain.go index dbecc1e..8ad3bb2 100644 --- a/credentialAtomicQueryV3OnChain.go +++ b/credentialAtomicQueryV3OnChain.go @@ -466,7 +466,7 @@ type AtomicQueryV3OnChainPubSignals struct { func (ao *AtomicQueryV3OnChainPubSignals) GetStatesInfo() StatesInfo { return StatesInfo{ - States: []States{ + States: []State{ { ID: ao.IssuerID, State: ao.IssuerState, @@ -476,7 +476,7 @@ func (ao *AtomicQueryV3OnChainPubSignals) GetStatesInfo() StatesInfo { State: ao.IssuerClaimNonRevState, }, }, - Gists: []Gists{ + Gists: []Gist{ { ID: ao.UserID, Root: ao.GlobalRoot,