Skip to content

Commit

Permalink
compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Feb 9, 2024
1 parent b01093f commit d845f84
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
10 changes: 4 additions & 6 deletions json/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"

core "github.com/iden3/go-iden3-core/v2"
"github.com/iden3/go-schema-processor/v2/processor"
"github.com/iden3/go-schema-processor/v2/verifiable"
"github.com/piprate/json-gold/ld"
"github.com/pkg/errors"
Expand All @@ -20,8 +21,9 @@ type Parser struct {
// Deprecated: use credential.GetClaim instead
func (s Parser) ParseClaim(ctx context.Context,
credential verifiable.W3CCredential,
opts *verifiable.CoreClaimOptions) (*core.Claim, error) {
return credential.GetClaim(ctx, opts)
opts processor.CoreClaimOptions) (*core.Claim, error) {
verifiableOpts := verifiable.CoreClaimOptions(opts)
return credential.GetClaim(ctx, &verifiableOpts)
}

// GetFieldSlotIndex return index of slot from 0 to 7 (each claim has by default 8 slots)
Expand Down Expand Up @@ -77,7 +79,3 @@ func (s Parser) GetFieldSlotIndex(field string, typeName string,
"field `%s` not specified in serialization info", field)
}
}

// CoreClaimOptions is params for core claim parsing
// Deprecated: use verifiable.CoreClaimOptions instead
type CoreClaimOptions verifiable.CoreClaimOptions
9 changes: 5 additions & 4 deletions json/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

core "github.com/iden3/go-iden3-core/v2"
"github.com/iden3/go-schema-processor/v2/merklize"
"github.com/iden3/go-schema-processor/v2/processor"
tst "github.com/iden3/go-schema-processor/v2/testing"
"github.com/iden3/go-schema-processor/v2/verifiable"
"github.com/stretchr/testify/require"
Expand All @@ -31,15 +32,15 @@ func TestParser_ParseClaimWithDataSlots(t *testing.T) {

parser := Parser{}

opts := verifiable.CoreClaimOptions{
opts := processor.CoreClaimOptions{
RevNonce: 127366661,
Version: 0,
SubjectPosition: verifiable.CredentialSubjectPositionIndex,
MerklizedRootPosition: verifiable.CredentialMerklizedRootPositionNone,
Updatable: true,
}

claim, err := parser.ParseClaim(context.Background(), credential, &opts)
claim, err := parser.ParseClaim(context.Background(), credential, opts)
require.NoError(t, err)

index, value := claim.RawSlots()
Expand Down Expand Up @@ -76,14 +77,14 @@ func TestParser_ParseClaimWithMerklizedRoot(t *testing.T) {

parser := Parser{}

opts := verifiable.CoreClaimOptions{
opts := processor.CoreClaimOptions{
RevNonce: 127366661,
Version: 0,
SubjectPosition: verifiable.CredentialSubjectPositionIndex,
MerklizedRootPosition: verifiable.CredentialMerklizedRootPositionIndex,
Updatable: true,
}
claim, err := parser.ParseClaim(context.Background(), credential, &opts)
claim, err := parser.ParseClaim(context.Background(), credential, opts)
require.NoError(t, err)

index, value := claim.RawSlots()
Expand Down
8 changes: 6 additions & 2 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ type Validator interface {
// Parser is an interface to parse claim slots
type Parser interface {
ParseClaim(ctx context.Context, credential verifiable.W3CCredential,
options *verifiable.CoreClaimOptions) (*core.Claim, error)
options CoreClaimOptions) (*core.Claim, error)
GetFieldSlotIndex(field string, typeName string, schema []byte) (int, error)
}

// CoreClaimOptions is params for core claim parsing
// Deprecated: use verifiable.CoreClaimOptions instead
type CoreClaimOptions verifiable.CoreClaimOptions

var (
errParserNotDefined = errors.New("parser is not defined")
errLoaderNotDefined = errors.New("loader is not defined")
Expand Down Expand Up @@ -82,7 +86,7 @@ func (s *Processor) Load(ctx context.Context, url string) (schema []byte, err er
// ParseClaim will serialize input data to index and value fields.
func (s *Processor) ParseClaim(ctx context.Context,
credential verifiable.W3CCredential,
opts *verifiable.CoreClaimOptions) (*core.Claim, error) {
opts CoreClaimOptions) (*core.Claim, error) {

if s.Parser == nil {
return nil, errParserNotDefined
Expand Down

0 comments on commit d845f84

Please sign in to comment.