From f5b1b1bce5e371f5a28ac342e69715adfd7f1488 Mon Sep 17 00:00:00 2001 From: ilya-korotya Date: Wed, 11 May 2022 18:25:54 +0300 Subject: [PATCH 1/2] add subject position to credential struct --- verifiable/credential.go | 1 + 1 file changed, 1 insertion(+) diff --git a/verifiable/credential.go b/verifiable/credential.go index 8d3bbc0..55ac56d 100644 --- a/verifiable/credential.go +++ b/verifiable/credential.go @@ -17,6 +17,7 @@ type Iden3Credential struct { RevNonce uint64 `json:"rev_nonce"` CredentialSubject map[string]interface{} `json:"credentialSubject"` CredentialStatus *CredentialStatus `json:"credentialStatus,omitempty"` + SubjectPosition string `json:"subject_position,omitempty"` CredentialSchema struct { ID string `json:"@id"` Type string `json:"type"` From 02a50e6909b71e3cd9cf3606207910046c0303f0 Mon Sep 17 00:00:00 2001 From: ilya-korotya Date: Thu, 12 May 2022 14:43:10 +0300 Subject: [PATCH 2/2] 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