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

Feature/VerifyToken #76

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
107 changes: 86 additions & 21 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/ethereum/go-ethereum/ethclient"
"github.com/google/uuid"
"github.com/iden3/contracts-abi/state/go/abi"
"github.com/iden3/driver-did-iden3/pkg/services/blockchain/eth"
"github.com/iden3/go-circuits/v2"
"github.com/iden3/go-iden3-auth/v2/loaders"
"github.com/iden3/go-iden3-auth/v2/proofs"
Expand Down Expand Up @@ -100,6 +101,7 @@ type Verifier struct {
verificationKeyLoader loaders.VerificationKeyLoader
documentLoader ld.DocumentLoader
stateResolver map[string]pubsignals.StateResolver
ethResolvers map[int]eth.Resolver
packageManager iden3comm.PackageManager
}

Expand Down Expand Up @@ -139,17 +141,46 @@ func WithDIDResolver(resolver packers.DIDResolverHandlerFunc) VerifierOption {
}
}

// WithEthereumResolvers set the ethereum resolvers to use. It will overwrite the
// default ones.
func WithEthereumResolvers(resolvers map[int]eth.Resolver) VerifierOption {
return func(opts *verifierOpts) {
opts.ethResolvers = resolvers
}
}

type verifierOpts struct {
docLoader ld.DocumentLoader
ipfsCli schemaloaders.IPFSClient
ipfsGW string
didResolver packers.DIDResolverHandlerFunc
docLoader ld.DocumentLoader
ipfsCli schemaloaders.IPFSClient
ipfsGW string
didResolver packers.DIDResolverHandlerFunc
ethResolvers map[int]eth.Resolver
}

func newOpts() verifierOpts {
return verifierOpts{
didResolver: UniversalDIDResolver,
func defaultEthResolver() (map[int]eth.Resolver, error) {
const (
chainID = 21000
rpc = "https://rpc-mainnet.privado.id"
contractAddr = "0x58485809CfAc875B7E6F54E3fCb5f24614f202e9"
)
r, err := eth.NewResolver(rpc, contractAddr)
if err != nil {
return nil, err
}
return map[int]eth.Resolver{
chainID: *r,
}, nil
}

func newOpts() (verifierOpts, error) {
ethRes, err := defaultEthResolver()
if err != nil {
return verifierOpts{}, err
}
return verifierOpts{
didResolver: UniversalDIDResolver,
ethResolvers: ethRes,
}, nil
}

// NewVerifier returns setup instance of auth library
Expand All @@ -158,7 +189,10 @@ func NewVerifier(
resolver map[string]pubsignals.StateResolver,
opts ...VerifierOption,
) (*Verifier, error) {
vOpts := newOpts()
vOpts, err := newOpts()
if err != nil {
return nil, err
}
for _, optFn := range opts {
optFn(&vOpts)
}
Expand All @@ -168,11 +202,12 @@ func NewVerifier(
v := &Verifier{
verificationKeyLoader: keyLoader,
documentLoader: docLoader,
ethResolvers: vOpts.ethResolvers,
stateResolver: resolver,
packageManager: *iden3comm.NewPackageManager(),
}

err := v.SetupAuthV2ZKPPacker()
err = v.SetupAuthV2ZKPPacker()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -238,7 +273,7 @@ func (v *Verifier) SetupAuthV2ZKPPacker() error {
// SetupJWSPacker sets the JWS packer for the VerifierBuilder.
func (v *Verifier) SetupJWSPacker(didResolver packers.DIDResolverHandlerFunc) error {

signerFnStub := packers.SignerResolverHandlerFunc(func(kid string) (crypto.Signer, error) {
signerFnStub := packers.SignerResolverHandlerFunc(func(_ string) (crypto.Signer, error) {
return nil, nil
})
jwsPacker := packers.NewJWSPacker(didResolver, signerFnStub)
Expand Down Expand Up @@ -288,6 +323,7 @@ func CreateContractInvokeRequest(
}

// CreateContractInvokeRequestWithMessage creates new contract invoke request message with message
// Deprecated:
func CreateContractInvokeRequestWithMessage(
reason, message, sender string,
transactionData protocol.TransactionData,
Expand All @@ -302,7 +338,6 @@ func CreateContractInvokeRequestWithMessage(
From: sender,
Body: protocol.ContractInvokeRequestMessageBody{
Reason: reason,
Message: message,
TransactionData: transactionData,
Scope: zkRequests,
},
Expand Down Expand Up @@ -475,7 +510,7 @@ func (v *Verifier) VerifyAuthResponse(
return err
}

err = verifyGroupIDMathch(verifyResult.LinkID, query.GroupID, proofResponse.ID, groupIDToLinkIDMap)
err = verifyGroupIDMatch(verifyResult.LinkID, query.GroupID, proofResponse.ID, groupIDToLinkIDMap)
if err != nil {
return err
}
Expand All @@ -485,7 +520,7 @@ func (v *Verifier) VerifyAuthResponse(
return nil
}

func verifyGroupIDMathch(linkID *big.Int, groupID int, requestID uint32, groupIDToLinkIDMap map[int][]linkIDRequestID) error {
func verifyGroupIDMatch(linkID *big.Int, groupID int, requestID uint32, groupIDToLinkIDMap map[int][]linkIDRequestID) error {
if groupID == 0 {
return nil
}
Expand Down Expand Up @@ -517,6 +552,7 @@ func verifyGroupIDMathch(linkID *big.Int, groupID int, requestID uint32, groupID
}

// VerifyJWZ performs verification of jwz token
// Deprecated: Use VerifyToken instead
func (v *Verifier) VerifyJWZ(
ctx context.Context,
token string,
Expand Down Expand Up @@ -553,15 +589,29 @@ func (v *Verifier) VerifyJWZ(
return t, err
}

// FullVerify performs verification of jwz token and auth request
func (v *Verifier) FullVerify(
ctx context.Context,
// VerifyToken performs verification of jws/jwz token using the registered packers in package manager
func (v *Verifier) VerifyToken(
token string,
request protocol.AuthorizationRequestMessage,
opts ...pubsignals.VerifyOpt, // TODO(illia-korotia): is ok have common option for VerifyJWZ and VerifyAuthResponse?
opts ...packers.DefaultZKPUnpackerOption,
) (*protocol.AuthorizationResponseMessage, error) {

msg, _, err := v.packageManager.Unpack([]byte(token))
pm := v.packageManager.Clone()
if opts != nil {
authV2Set, err := v.verificationKeyLoader.Load(circuits.AuthV2CircuitID)
if err != nil {
return nil, fmt.Errorf("failed upload circuits files: %w", err)
}

if err := pm.UpdatePacker(
packers.DefaultZKPUnpacker(
authV2Set,
v.ethResolvers,
opts...)); err != nil {
return nil, fmt.Errorf("failed to update packer: %w", err)
}
}

msg, _, err := pm.Unpack([]byte(token))
if err != nil {
return nil, err
}
Expand All @@ -576,11 +626,26 @@ func (v *Verifier) FullVerify(
if err != nil {
return nil, err
}

err = v.VerifyAuthResponse(ctx, authMsgResponse, request, opts...)
return &authMsgResponse, err
}

// FullVerify performs verification of jwz token and auth request
func (v *Verifier) FullVerify(
ctx context.Context,
token string,
request protocol.AuthorizationRequestMessage,
opts ...pubsignals.VerifyOpt, // TODO(illia-korotia): is ok have common option for VerifyJWZ and VerifyAuthResponse?
) (*protocol.AuthorizationResponseMessage, error) {

authMsgResponse, err := v.VerifyToken(token)
if err != nil {
return nil, err
}

err = v.VerifyAuthResponse(ctx, *authMsgResponse, request, opts...)
return authMsgResponse, err
}

// VerifyState allows to verify state without binding to verifier instance
func VerifyState(ctx context.Context, id, s *big.Int, opts state.ExtendedVerificationsOptions) error {

Expand Down
66 changes: 66 additions & 0 deletions auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"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"
"github.com/iden3/iden3comm/v2/packers"
"github.com/iden3/iden3comm/v2/protocol"
"github.com/piprate/json-gold/ld"
Expand Down Expand Up @@ -422,6 +423,71 @@ func TestVerifier_VerifyJWZ(t *testing.T) {
schemaLoader.assert(t)
}

func TestVerifier_VerifyToken(t *testing.T) {
// tokenJWZ := `eyJhbGciOiJncm90aDE2IiwiY2lyY3VpdElkIjoiYXV0aFYyIiwiY3JpdCI6WyJjaXJjdWl0SWQiXSwidHlwIjoiYXBwbGljYXRpb24vaWRlbjMtemtwLWpzb24ifQ.eyJpZCI6IjljMGY5NjIzLWM1NmMtNDEwNC04ODk2LWVjMjgyYTNiMmExNyIsInR5cCI6ImFwcGxpY2F0aW9uL2lkZW4zY29tbS1wbGFpbi1qc29uIiwidHlwZSI6Imh0dHBzOi8vaWRlbjMtY29tbXVuaWNhdGl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IjAiLCIwIiwiMCIsIjAiXX1dfSwiZnJvbSI6ImRpZDpwa2g6cG9seToweDcxNDFFNGQyMEY3NjQ0REM4YzBBZENBOGE1MjBFQzgzQzZjQUJENjUiLCJ0byI6ImRpZDpwb2x5Z29uaWQ6cG9seWdvbjptdW1iYWk6MnFMUHF2YXlOUXo5VEEycjVWUHhVdWdvRjE4dGVHVTU4M3pKODU5d2Z5In0.bWc2ECABj7nvHatD8AXWNJM2VtfhkIjNwz5BBIK9zBMsP0-UWLEWdAWcosiLkYoL0KWwZpgEOrPPepl6T5gC-AA`

schemaLoader := &mockJSONLDSchemaLoader{}
authInstance, err := NewVerifier(verificationKeyloader, stateResolvers, WithDocumentLoader(schemaLoader))
require.NoError(t, err)

type expected struct {
err bool
Typ iden3comm.MediaType
From string
To string
}
for _, tc := range []struct {
name string
token string
expected expected
}{
{
name: "Verify JWS token",
token: tokenJWS,
expected: expected{
Typ: packers.MediaTypeSignedMessage,
From: "did:pkh:poly:0x7141E4d20F7644DC8c0AdCA8a520EC83C6cABD65",
To: "did:polygonid:polygon:mumbai:2qLPqvayNQz9TA2r5VPxUugoF18teGU583zJ859wfy",
},
},
{
name: "Verify JWZ token",
token: tokenJWZPrivadoMain,
expected: expected{
Typ: packers.MediaTypePlainMessage,
From: "did:polygonid:polygon:mumbai:2qPDLXDaU1xa1ERTb1XKBfPCB3o2wA46q49neiXWwY",
To: "did:polygonid:polygon:mumbai:2qJ689kpoJxcSzB5sAFJtPsSBSrHF5dq722BHMqURL",
},
},
{
name: "Wrong token",
token: "wrongtoken",
expected: expected{
err: true,
},
},
{
name: "A dummy JWT token",
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
expected: expected{
err: true,
},
},
} {
t.Run(tc.name, func(t *testing.T) {
authResp, err := authInstance.VerifyToken(tc.token, packers.WithAuthVerifyDelay(5*time.Second))
require.Equal(t, tc.expected.err, err != nil)
if err == nil {
assert.Equal(t, tc.expected.Typ, authResp.Typ)
assert.Equal(t, tc.expected.From, authResp.From)
assert.Equal(t, tc.expected.To, authResp.To)
}
})
}
}

func TestVerifier_FullVerify(t *testing.T) {
// request
verifierID := "did:polygonid:polygon:mumbai:2qJ689kpoJxcSzB5sAFJtPsSBSrHF5dq722BHMqURL"
Expand Down
Loading
Loading