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 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"`