Skip to content

Commit

Permalink
Merge pull request #20 from iden3/feature/IDEN-298-add-subject-positi…
Browse files Browse the repository at this point in the history
…on-to-claim

IDEN-298: add subject position to credential struct
  • Loading branch information
ilya-korotya authored May 19, 2022
2 parents c72d839 + 02a50e6 commit 3c4dd9c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
11 changes: 10 additions & 1 deletion json-ld/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion json/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions utils/claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions verifiable/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 3c4dd9c

Please sign in to comment.