Skip to content

Commit

Permalink
Refactor URA credential generation and naming conventions
Browse files Browse the repository at this point in the history
Updated the uraCredential function to use 'issuer' instead of 'did' for the issuer parameter and simplified the mapping of credential subjects. Also, standardized the constant naming for SAN_TYPE_OTHER_NAME to SanTypeOtherName across the codebase to ensure consistency.
  • Loading branch information
rolandgroen committed Nov 1, 2024
1 parent fb97cfd commit d7de4f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions uzi_vc_issuer/ura_issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,30 +255,28 @@ 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(did string, otherNameValue string, serialNumber string, subjectDID string) (*vc.VerifiableCredential, error) {
func uraCredential(issuer string, otherNameValue string, serialNumber string, subjectDID string) (*vc.VerifiableCredential, error) {
exp := time.Now().Add(time.Hour * 24 * 365 * 100)
iat := time.Now()
uzi, ura, agb, err := x509_cert.ParseUraFromOtherNameValue(otherNameValue)
uzi, _, _, err := x509_cert.ParseUraFromOtherNameValue(otherNameValue)
if err != nil {
return nil, err
}
if uzi != serialNumber {
return nil, errors.New("serial number does not match UZI number")
}
return &vc.VerifiableCredential{
Issuer: ssi.MustParseURI(did),
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,
"uraNumber": ura,
"otherName": uzi,
"uziNumber": serialNumber,
"agbNumber": agb,
"id": subjectDID,
"serialNumber": serialNumber,
"otherName": otherNameValue,
},
},
}, nil
Expand Down
2 changes: 1 addition & 1 deletion x509_cert/x509_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func FindOtherName(certificate *x509.Certificate) (string, SanTypeName, error) {
return "", "", err
}
if otherNameValue != "" {
return otherNameValue, SAN_TYPE_OTHER_NAME, nil
return otherNameValue, SanTypeOtherName, nil
}
err = errors.New("no otherName found in the SAN attributes, please check if the certificate is an UZI Server Certificate")
return "", "", err
Expand Down

0 comments on commit d7de4f9

Please sign in to comment.