Skip to content

Commit

Permalink
Refactor uraCredential to add the otherName values dynamically.
Browse files Browse the repository at this point in the history
Removed the redundant serialNumber parameter from the `uraCredential` function to streamline its usage. Adjusted the function internals accordingly to handle the credentials more effectively, ensuring the subject's DID and other name values are managed in a consolidated manner.
  • Loading branch information
rolandgroen committed Nov 1, 2024
1 parent 5a0db44 commit 4e6a75b
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions uzi_vc_issuer/ura_issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func BuildUraVerifiableCredential(chain []*x509.Certificate, signingKey *rsa.Pri
if uzi != serialNumber {
return nil, errors.New("serial number does not match UZI number")
}
template, err := uraCredential(did, otherNameValues, serialNumber, subjectDID)
template, err := uraCredential(did, otherNameValues, subjectDID)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -263,25 +263,23 @@ func convertHeaders(headers map[string]interface{}) (jws.Headers, error) {

// uraCredential generates a VerifiableCredential for a given URA and UZI number, including the subject's DID.
// It sets a 1-year expiration period from the current issuance date.
func uraCredential(issuer string, otherNameValues []*x509_cert.OtherNameValue, serialNumber string, subjectDID string) (*vc.VerifiableCredential, error) {
func uraCredential(issuer string, otherNameValues []*x509_cert.OtherNameValue, subjectDID string) (*vc.VerifiableCredential, error) {
exp := time.Now().Add(time.Hour * 24 * 365 * 100)
iat := time.Now()
stringValue, err := x509_cert.FindOtherNameValue(otherNameValues, x509_cert.PolicyTypeSan, x509_cert.SanTypeOtherName)
if err != nil {
return nil, err
subject := map[x509_cert.SanTypeName]interface{}{
"id": subjectDID,
}
for _, otherNameValue := range otherNameValues {
subject[otherNameValue.Type] = otherNameValue.Value
}

return &vc.VerifiableCredential{
Issuer: ssi.MustParseURI(issuer),
Context: []ssi.URI{ssi.MustParseURI("https://www.w3.org/2018/credentials/v1")},
Type: []ssi.URI{ssi.MustParseURI("VerifiableCredential"), ssi.MustParseURI("UziServerCertificateCredential")},
ID: func() *ssi.URI { id := ssi.MustParseURI(uuid.NewString()); return &id }(),
IssuanceDate: iat,
ExpirationDate: &exp,
CredentialSubject: []interface{}{
map[string]interface{}{
"id": subjectDID,
"otherName": stringValue,
},
},
Issuer: ssi.MustParseURI(issuer),
Context: []ssi.URI{ssi.MustParseURI("https://www.w3.org/2018/credentials/v1")},
Type: []ssi.URI{ssi.MustParseURI("VerifiableCredential"), ssi.MustParseURI("UziServerCertificateCredential")},
ID: func() *ssi.URI { id := ssi.MustParseURI(uuid.NewString()); return &id }(),
IssuanceDate: iat,
ExpirationDate: &exp,
CredentialSubject: []interface{}{subject},
}, nil
}

0 comments on commit 4e6a75b

Please sign in to comment.