Skip to content

Commit

Permalink
Fix/not to brake compatability (#48)
Browse files Browse the repository at this point in the history
* introduce new function to not break compatibility

---------

Co-authored-by: Oleg Lomaka <[email protected]>
  • Loading branch information
vmidyllic and olomix authored Jun 19, 2023
1 parent 16a146e commit 09a7e10
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ The blockchain verification algorithm is used
"polygon:mumbai": resolver,
}
verifier := auth.NewVerifier(verificationKeyloader, loaders.DefaultSchemaLoader{IpfsURL: "ipfs.io"}, resolvers)
```
// check that verifier instance is not nil or use NewVerifierWithExplicitError and check error
// verifier,err := auth.NewVerifierWithExplicitError(verificationKeyloader, loaders.DefaultSchemaLoader{IpfsURL: "ipfs.io"}, resolvers)
```
4. FullVerify:

```go
Expand Down
33 changes: 31 additions & 2 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"crypto"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"math/big"
"net/http"
Expand Down Expand Up @@ -48,7 +48,7 @@ var UniversalDIDResolver = packers.DIDResolverHandlerFunc(func(did string) (*ver
}
}()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -90,10 +90,39 @@ type Verifier struct {
}

// NewVerifier returns setup instance of auth library
// Deprecated: NewVerifier now return nil it can't set up default package manager for verifier,
// in future major release it will return error
func NewVerifier(
keyLoader loaders.VerificationKeyLoader,
claimSchemaLoader loaders.SchemaLoader,
resolver map[string]pubsignals.StateResolver,
) *Verifier {
v := &Verifier{
verificationKeyLoader: keyLoader,
claimSchemaLoader: claimSchemaLoader,
stateResolver: resolver,
packageManager: *iden3comm.NewPackageManager(),
}

err := v.SetupAuthV2ZKPPacker()
if err != nil {
return nil
}

err = v.SetupJWSPacker(UniversalDIDResolver)
if err != nil {
return nil
}

return v
}

// NewVerifierWithExplicitError returns verifier instance with default package manager and explicit error if it couldn't register default packers
// in future major release it will be renamed to NewVerifier
func NewVerifierWithExplicitError(
keyLoader loaders.VerificationKeyLoader,
claimSchemaLoader loaders.SchemaLoader,
resolver map[string]pubsignals.StateResolver,
) (*Verifier, error) {
v := &Verifier{
verificationKeyLoader: keyLoader,
Expand Down
Loading

0 comments on commit 09a7e10

Please sign in to comment.