Skip to content

Commit

Permalink
undo "move verifier to go-circuits"
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Nov 2, 2023
1 parent b9af7ca commit 97ee431
Show file tree
Hide file tree
Showing 13 changed files with 849 additions and 117 deletions.
15 changes: 7 additions & 8 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/google/uuid"
"github.com/iden3/contracts-abi/state/go/abi"
"github.com/iden3/go-circuits/v2"
verifier "github.com/iden3/go-circuits/v2/verifier"
"github.com/iden3/go-iden3-auth/v2/loaders"
"github.com/iden3/go-iden3-auth/v2/proofs"
"github.com/iden3/go-iden3-auth/v2/pubsignals"
Expand Down Expand Up @@ -100,7 +99,7 @@ var UniversalDIDResolver = packers.DIDResolverHandlerFunc(func(did string) (*ver
type Verifier struct {
verificationKeyLoader loaders.VerificationKeyLoader
documentLoader ld.DocumentLoader
stateResolver map[string]verifier.StateResolver
stateResolver map[string]pubsignals.StateResolver
packageManager iden3comm.PackageManager
}

Expand Down Expand Up @@ -156,7 +155,7 @@ func newOpts() verifierOpts {
// NewVerifier returns setup instance of auth library
func NewVerifier(
keyLoader loaders.VerificationKeyLoader,
resolver map[string]verifier.StateResolver,
resolver map[string]pubsignals.StateResolver,
opts ...VerifierOption,
) (*Verifier, error) {
vOpts := newOpts()
Expand Down Expand Up @@ -315,7 +314,7 @@ func (v *Verifier) VerifyAuthResponse(
ctx context.Context,
response protocol.AuthorizationResponseMessage,
request protocol.AuthorizationRequestMessage,
opts ...verifier.VerifyOpt,
opts ...pubsignals.VerifyOpt,
) error {

if request.Body.Message != response.Body.Message {
Expand Down Expand Up @@ -350,7 +349,7 @@ func (v *Verifier) VerifyAuthResponse(
if err != nil {
return err
}
var query verifier.Query
var query pubsignals.Query
err = json.Unmarshal(queryBytes, &query)
if err != nil {
return err
Expand Down Expand Up @@ -394,7 +393,7 @@ func (v *Verifier) VerifyAuthResponse(
func (v *Verifier) VerifyJWZ(
ctx context.Context,
token string,
opts ...verifier.VerifyOpt,
opts ...pubsignals.VerifyOpt,
) (t *jwz.Token, err error) {

t, err = jwz.Parse(token)
Expand Down Expand Up @@ -432,7 +431,7 @@ func (v *Verifier) FullVerify(
ctx context.Context,
token string,
request protocol.AuthorizationRequestMessage,
opts ...verifier.VerifyOpt, // TODO(illia-korotia): is ok have common option for VerifyJWZ and VerifyAuthResponse?
opts ...pubsignals.VerifyOpt, // TODO(illia-korotia): is ok have common option for VerifyJWZ and VerifyAuthResponse?
) (*protocol.AuthorizationResponseMessage, error) {

msg, _, err := v.packageManager.Unpack([]byte(token))
Expand Down Expand Up @@ -485,7 +484,7 @@ func VerifyState(ctx context.Context, id, s *big.Int, opts state.ExtendedVerific

}

func getPublicSignalsVerifier(circuitID circuits.CircuitID, signals []string) (verifier.Verifier, error) {
func getPublicSignalsVerifier(circuitID circuits.CircuitID, signals []string) (pubsignals.Verifier, error) {
pubSignalBytes, err := json.Marshal(signals)
if err != nil {
return nil, err
Expand Down
31 changes: 16 additions & 15 deletions auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (

"github.com/google/uuid"
"github.com/iden3/go-circuits/v2"
verifier "github.com/iden3/go-circuits/v2/verifier"
"github.com/iden3/go-iden3-auth/v2/loaders"
"github.com/iden3/go-iden3-auth/v2/pubsignals"
"github.com/iden3/go-iden3-auth/v2/state"
"github.com/iden3/go-rapidsnark/types"
"github.com/iden3/go-schema-processor/v2/verifiable"
"github.com/iden3/iden3comm/v2/packers"
Expand Down Expand Up @@ -58,7 +59,7 @@ func (r *mockJSONLDSchemaLoader) assert(t testing.TB) {
/*
mock for state resolver
*/
var stateResolvers = map[string]verifier.StateResolver{
var stateResolvers = map[string]pubsignals.StateResolver{
"polygon:mumbai": &mockStateResolver{},
}

Expand All @@ -67,12 +68,12 @@ const proofGenerationDelay = time.Hour * 100000
type mockStateResolver struct {
}

func (r *mockStateResolver) Resolve(_ context.Context, _, _ *big.Int) (*verifier.ResolvedState, error) {
return &verifier.ResolvedState{Latest: true, Genesis: false, TransitionTimestamp: 0}, nil
func (r *mockStateResolver) Resolve(_ context.Context, _, _ *big.Int) (*state.ResolvedState, error) {
return &state.ResolvedState{Latest: true, Genesis: false, TransitionTimestamp: 0}, nil
}

func (r *mockStateResolver) ResolveGlobalRoot(_ context.Context, _ *big.Int) (*verifier.ResolvedState, error) {
return &verifier.ResolvedState{Latest: true, TransitionTimestamp: 0}, nil
func (r *mockStateResolver) ResolveGlobalRoot(_ context.Context, _ *big.Int) (*state.ResolvedState, error) {
return &state.ResolvedState{Latest: true, TransitionTimestamp: 0}, nil
}

func TestVerifyMessageWithSigProof_NonMerkalized(t *testing.T) {
Expand Down Expand Up @@ -235,7 +236,7 @@ func TestVerifyMessageWithSigProof_NonMerkalized(t *testing.T) {
WithDocumentLoader(schemaLoader))
require.NoError(t, err)
err = authInstance.VerifyAuthResponse(context.Background(), message, request,
verifier.WithAcceptedProofGenerationDelay(proofGenerationDelay))
pubsignals.WithAcceptedProofGenerationDelay(proofGenerationDelay))
require.Nil(t, err)
schemaLoader.assert(t)
}
Expand Down Expand Up @@ -402,7 +403,7 @@ func TestVerifyMessageWithMTPProof_Merkalized(t *testing.T) {
authInstance, err := NewVerifier(verificationKeyloader, stateResolvers,
WithDocumentLoader(schemaLoader))
require.NoError(t, err)
err = authInstance.VerifyAuthResponse(context.Background(), message, request, verifier.WithAcceptedProofGenerationDelay(proofGenerationDelay))
err = authInstance.VerifyAuthResponse(context.Background(), message, request, pubsignals.WithAcceptedProofGenerationDelay(proofGenerationDelay))
require.NoError(t, err)
schemaLoader.assert(t)
}
Expand Down Expand Up @@ -462,7 +463,7 @@ func TestVerifier_FullVerify(t *testing.T) {
authInstance, err := NewVerifier(verificationKeyloader, stateResolvers,
WithDocumentLoader(schemaLoader))
require.NoError(t, err)
_, err = authInstance.FullVerify(context.Background(), token, request, verifier.WithAcceptedProofGenerationDelay(proofGenerationDelay))
_, err = authInstance.FullVerify(context.Background(), token, request, pubsignals.WithAcceptedProofGenerationDelay(proofGenerationDelay))
require.NoError(t, err)
schemaLoader.assert(t)
}
Expand Down Expand Up @@ -512,7 +513,7 @@ func TestVerifier_FullVerify_JWS(t *testing.T) {
WithDocumentLoader(schemaLoader),
WithDIDResolver(mockedResolver))
require.NoError(t, err)
_, err = v.FullVerify(context.Background(), token, request, verifier.WithAcceptedProofGenerationDelay(proofGenerationDelay))
_, err = v.FullVerify(context.Background(), token, request, pubsignals.WithAcceptedProofGenerationDelay(proofGenerationDelay))
require.NoError(t, err)

schemaLoader.assert(t)
Expand Down Expand Up @@ -675,7 +676,7 @@ func TestVerifyAuthResponseWithEmptyReq(t *testing.T) {
WithDocumentLoader(schemaLoader))
require.NoError(t, err)
err = authInstance.VerifyAuthResponse(context.Background(), resp, authReq,
verifier.WithAcceptedProofGenerationDelay(proofGenerationDelay))
pubsignals.WithAcceptedProofGenerationDelay(proofGenerationDelay))
require.NoError(t, err)
schemaLoader.assert(t)
}
Expand Down Expand Up @@ -744,7 +745,7 @@ func TestVerifier_FullVerifySelectiveDisclosure(t *testing.T) {
authInstance, err := NewVerifier(verificationKeyloader, stateResolvers,
WithDocumentLoader(schemaLoader))
require.NoError(t, err)
_, err = authInstance.FullVerify(context.Background(), token, request, verifier.WithAcceptedProofGenerationDelay(proofGenerationDelay))
_, err = authInstance.FullVerify(context.Background(), token, request, pubsignals.WithAcceptedProofGenerationDelay(proofGenerationDelay))
require.NoError(t, err)
schemaLoader.assert(t)
}
Expand Down Expand Up @@ -780,7 +781,7 @@ func TestEmptyCredentialSubject(t *testing.T) {
authInstance, err := NewVerifier(verificationKeyloader, stateResolvers,
WithDocumentLoader(schemaLoader))
require.NoError(t, err)
_, err = authInstance.FullVerify(context.Background(), token, request, verifier.WithAcceptedProofGenerationDelay(proofGenerationDelay))
_, err = authInstance.FullVerify(context.Background(), token, request, pubsignals.WithAcceptedProofGenerationDelay(proofGenerationDelay))
require.NoError(t, err)

schemaLoader.assert(t)
Expand Down Expand Up @@ -960,7 +961,7 @@ func TestVerifyV3MessageWithSigProof_NonMerkalized(t *testing.T) {
WithDocumentLoader(schemaLoader))
require.NoError(t, err)
err = authInstance.VerifyAuthResponse(context.Background(), message, request,
verifier.WithAcceptedProofGenerationDelay(proofGenerationDelay))
pubsignals.WithAcceptedProofGenerationDelay(proofGenerationDelay))
require.Nil(t, err)
schemaLoader.assert(t)
}
Expand Down Expand Up @@ -1132,7 +1133,7 @@ func TestVerifyV3MessageWithMtpProof_Merkalized(t *testing.T) {
WithDocumentLoader(schemaLoader))
require.NoError(t, err)
err = authInstance.VerifyAuthResponse(context.Background(), message, request,
verifier.WithAcceptedProofGenerationDelay(proofGenerationDelay))
pubsignals.WithAcceptedProofGenerationDelay(proofGenerationDelay))
require.Nil(t, err)
schemaLoader.assert(t)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
github.com/iden3/contracts-abi/state/go/abi v1.0.0-beta.3
github.com/iden3/go-circuits/v2 v2.0.1-0.20231101090223-c0f146e654ef
github.com/iden3/go-circuits/v2 v2.0.1-0.20231004131331-7fe871d849fa
github.com/iden3/go-iden3-core/v2 v2.0.0
github.com/iden3/go-jwz/v2 v2.0.0
github.com/iden3/go-rapidsnark/types v0.0.3
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/huin/goupnp v1.2.0 h1:uOKW26NG1hsSSbXIZ1IR7XP9Gjd1U8pnLaCMgntmkmY=
github.com/iden3/contracts-abi/state/go/abi v1.0.0-beta.3 h1:ZHFnK2dU3NJglY+igY48JLHWtNGN/Vhf5/L/qrFk/tM=
github.com/iden3/contracts-abi/state/go/abi v1.0.0-beta.3/go.mod h1:TxgIrXCvxms3sbOdsy8kTvffUCIpEEifNy0fSXdkU4w=
github.com/iden3/go-circuits/v2 v2.0.0 h1:Bw0mpsqeip06d6I2ktgfhTVB7Jk9mSHi8myHZWkoc6w=
github.com/iden3/go-circuits/v2 v2.0.0/go.mod h1:VIFIp51+IH0hOzjnKhb84bCeyq7hq76zX/C14ua6zh4=
github.com/iden3/go-circuits/v2 v2.0.1-0.20231004131331-7fe871d849fa h1:NnqNskdeqvv81HD8kq6TMXukH63nguWR7/kwJyXVprY=
github.com/iden3/go-circuits/v2 v2.0.1-0.20231004131331-7fe871d849fa/go.mod h1:VIFIp51+IH0hOzjnKhb84bCeyq7hq76zX/C14ua6zh4=
github.com/iden3/go-circuits/v2 v2.0.1-0.20231030121612-9a682c3832b8 h1:aruiyZmwdIdCzPiLkYV9ZuXOWW1XXlneemGOojrXFvo=
github.com/iden3/go-circuits/v2 v2.0.1-0.20231030121612-9a682c3832b8/go.mod h1:DVpm13bEuckWj6yntsJLW3/HTiOnBGIBaM9KymNTvB0=
github.com/iden3/go-circuits/v2 v2.0.1-0.20231030142956-b67600ddac0e h1:Waqi6wl4WkOGPTqSWA6oFPASET8XPCxTN4KehJ1/XR4=
Expand Down
11 changes: 5 additions & 6 deletions pubsignals/atomicMtpV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/iden3/go-circuits/v2"
verifier "github.com/iden3/go-circuits/v2/verifier"
core "github.com/iden3/go-iden3-core/v2"
"github.com/iden3/go-iden3-core/v2/w3c"
"github.com/piprate/json-gold/ld"
Expand All @@ -23,12 +22,12 @@ type AtomicQueryMTPV2 struct {
// VerifyQuery checks whether the proof matches the query.
func (c *AtomicQueryMTPV2) VerifyQuery(
ctx context.Context,
query verifier.Query,
query Query,
schemaLoader ld.DocumentLoader,
verifiablePresentation json.RawMessage,
opts ...verifier.VerifyOpt,
opts ...VerifyOpt,
) error {
return query.Check(ctx, schemaLoader, &verifier.CircuitOutputs{
return query.Check(ctx, schemaLoader, &CircuitOutputs{
IssuerID: c.IssuerID,
ClaimSchema: c.ClaimSchema,
SlotIndex: c.SlotIndex,
Expand All @@ -45,7 +44,7 @@ func (c *AtomicQueryMTPV2) VerifyQuery(

// VerifyStates verifies user state and issuer claim issuance state in the smart contract.
func (c *AtomicQueryMTPV2) VerifyStates(ctx context.Context,
stateResolvers map[string]verifier.StateResolver, opts ...verifier.VerifyOpt) error {
stateResolvers map[string]StateResolver, opts ...VerifyOpt) error {

blockchain, err := core.BlockchainFromID(*c.IssuerID)
if err != nil {
Expand Down Expand Up @@ -76,7 +75,7 @@ func (c *AtomicQueryMTPV2) VerifyStates(ctx context.Context,
return err
}

cfg := verifier.DefaultProofVerifyOpts
cfg := DefaultProofVerifyOpts
for _, o := range opts {
o(&cfg)
}
Expand Down
11 changes: 5 additions & 6 deletions pubsignals/atomicSigV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/iden3/go-circuits/v2"
verifier "github.com/iden3/go-circuits/v2/verifier"
core "github.com/iden3/go-iden3-core/v2"
"github.com/iden3/go-iden3-core/v2/w3c"
"github.com/piprate/json-gold/ld"
Expand All @@ -23,12 +22,12 @@ type AtomicQuerySigV2 struct {
// VerifyQuery verifies query for atomic query mtp circuit.
func (c *AtomicQuerySigV2) VerifyQuery(
ctx context.Context,
query verifier.Query,
query Query,
schemaLoader ld.DocumentLoader,
verifiablePresentation json.RawMessage,
opts ...verifier.VerifyOpt,
opts ...VerifyOpt,
) error {
err := query.Check(ctx, schemaLoader, &verifier.CircuitOutputs{
err := query.Check(ctx, schemaLoader, &CircuitOutputs{
IssuerID: c.IssuerID,
ClaimSchema: c.ClaimSchema,
SlotIndex: c.SlotIndex,
Expand All @@ -48,7 +47,7 @@ func (c *AtomicQuerySigV2) VerifyQuery(
}

// VerifyStates verifies user state and issuer auth claim state in the smart contract.
func (c *AtomicQuerySigV2) VerifyStates(ctx context.Context, stateResolvers map[string]verifier.StateResolver, opts ...verifier.VerifyOpt) error {
func (c *AtomicQuerySigV2) VerifyStates(ctx context.Context, stateResolvers map[string]StateResolver, opts ...VerifyOpt) error {
blockchain, err := core.BlockchainFromID(*c.IssuerID)
if err != nil {
return err
Expand Down Expand Up @@ -79,7 +78,7 @@ func (c *AtomicQuerySigV2) VerifyStates(ctx context.Context, stateResolvers map[
return err
}

cfg := verifier.DefaultProofVerifyOpts
cfg := DefaultProofVerifyOpts
for _, o := range opts {
o(&cfg)
}
Expand Down
Loading

0 comments on commit 97ee431

Please sign in to comment.