Skip to content

Commit 3c4dd9c

Browse files
authored
Merge pull request #20 from iden3/feature/IDEN-298-add-subject-position-to-claim
IDEN-298: add subject position to credential struct
2 parents c72d839 + 02a50e6 commit 3c4dd9c

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

json-ld/parser.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,16 @@ func (p Parser) ParseClaim(credential *verifiable.Iden3Credential, schemaBytes [
9595
if err != nil {
9696
return nil, err
9797
}
98-
claim.SetIndexID(id)
98+
99+
switch credential.SubjectPosition {
100+
case "", utils.SubjectPositionIndex:
101+
claim.SetIndexID(id)
102+
case utils.SubjectPositionValue:
103+
claim.SetValueID(id)
104+
default:
105+
return nil, errors.New("unknown subject position")
106+
}
107+
99108
}
100109

101110
return claim, nil

json/parser.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,15 @@ func (s Parser) ParseClaim(credential *verifiable.Iden3Credential, schemaBytes [
6464
if err != nil {
6565
return nil, err
6666
}
67-
claim.SetIndexID(id)
67+
68+
switch credential.SubjectPosition {
69+
case "", utils.SubjectPositionIndex:
70+
claim.SetIndexID(id)
71+
case utils.SubjectPositionValue:
72+
claim.SetValueID(id)
73+
default:
74+
return nil, errors.New("unknown subject position")
75+
}
6876
}
6977

7078
return claim, nil

utils/claims.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ import (
1111
"github.com/pkg/errors"
1212
)
1313

14+
const (
15+
// SubjectPositionIndex save subject in index part of claim. By default.
16+
SubjectPositionIndex = "index"
17+
// SubjectPositionValue save subject in value part of claim.
18+
SubjectPositionValue = "value"
19+
)
20+
1421
var q *big.Int
1522

1623
//nolint //reason - needed

verifiable/credential.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Iden3Credential struct {
1717
RevNonce uint64 `json:"rev_nonce"`
1818
CredentialSubject map[string]interface{} `json:"credentialSubject"`
1919
CredentialStatus *CredentialStatus `json:"credentialStatus,omitempty"`
20+
SubjectPosition string `json:"subject_position,omitempty"`
2021
CredentialSchema struct {
2122
ID string `json:"@id"`
2223
Type string `json:"type"`

0 commit comments

Comments
 (0)