From 02a50e6909b71e3cd9cf3606207910046c0303f0 Mon Sep 17 00:00:00 2001 From: ilya-korotya Date: Thu, 12 May 2022 14:43:10 +0300 Subject: [PATCH] parse subject position --- json-ld/parser.go | 11 ++++++++++- json/parser.go | 10 +++++++++- utils/claims.go | 7 +++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/json-ld/parser.go b/json-ld/parser.go index e3d2828..75174e9 100644 --- a/json-ld/parser.go +++ b/json-ld/parser.go @@ -95,7 +95,16 @@ func (p Parser) ParseClaim(credential *verifiable.Iden3Credential, schemaBytes [ if err != nil { return nil, err } - claim.SetIndexID(id) + + switch credential.SubjectPosition { + case "", utils.SubjectPositionIndex: + claim.SetIndexID(id) + case utils.SubjectPositionValue: + claim.SetValueID(id) + default: + return nil, errors.New("unknown subject position") + } + } return claim, nil diff --git a/json/parser.go b/json/parser.go index fc80a67..dc5ede7 100644 --- a/json/parser.go +++ b/json/parser.go @@ -64,7 +64,15 @@ func (s Parser) ParseClaim(credential *verifiable.Iden3Credential, schemaBytes [ if err != nil { return nil, err } - claim.SetIndexID(id) + + switch credential.SubjectPosition { + case "", utils.SubjectPositionIndex: + claim.SetIndexID(id) + case utils.SubjectPositionValue: + claim.SetValueID(id) + default: + return nil, errors.New("unknown subject position") + } } return claim, nil diff --git a/utils/claims.go b/utils/claims.go index e1b6c1b..9c19fb1 100644 --- a/utils/claims.go +++ b/utils/claims.go @@ -11,6 +11,13 @@ import ( "github.com/pkg/errors" ) +const ( + // SubjectPositionIndex save subject in index part of claim. By default. + SubjectPositionIndex = "index" + // SubjectPositionValue save subject in value part of claim. + SubjectPositionValue = "value" +) + var q *big.Int //nolint //reason - needed