Skip to content

Commit

Permalink
Fix #61: Updates in OpenID4VP
Browse files Browse the repository at this point in the history
  • Loading branch information
josmilan committed Jan 27, 2025
1 parent b384209 commit e04bca8
Show file tree
Hide file tree
Showing 3 changed files with 395 additions and 217 deletions.
29 changes: 12 additions & 17 deletions Sources/eudiWalletOidcIos/Service/SDJWTService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,15 @@ public class SDJWTService {
}
public func createSDJWTR(
credential: String?,
presentationRequest: PresentationRequest,
privateKey: P256.Signing.PrivateKey
) -> String? {
inputDescriptor: InputDescriptor?, format: String?
, keyHandler: SecureKeyProtocol) -> String? {
do {
guard let credential = credential else {
return nil
}

let processedCredentialWithRequiredDisclosures = try processDisclosuresWithPresentationDefinition(
credential: credential,
presentationDefinition: VerificationService.processPresentationDefinition(presentationRequest.presentationDefinition)
)
credential: credential, inputDescriptor: inputDescriptor, format: format, keyHandler: keyHandler)

// let iat = Date()
// let payload =
Expand Down Expand Up @@ -83,19 +80,21 @@ public class SDJWTService {
}
public func processDisclosuresWithPresentationDefinition(
credential: String?,
presentationDefinition: PresentationDefinitionModel
) -> String? {
inputDescriptor: InputDescriptor?, format: String?, keyHandler: SecureKeyProtocol) -> String? {
guard let credential = credential else { return nil }

// Split the credential into disclosures and the issued JWT
guard let disclosures = getDisclosuresFromSDJWT(credential),
var issuedJwt = getIssuerJwtFromSDJWT(credential) else {
return nil
}
// if disclosures.count == 0 {
// return nil
// }
var disclosureList: [String] = []
// Extract requested parameters from the presentation definition
var requestedParams: [String] = []
if let fields = presentationDefinition.inputDescriptors?.first?.constraints?.fields {
if let fields = inputDescriptor?.constraints?.fields {
for field in fields {
if let paramName = field.path?.first?.split(separator: ".").last {
requestedParams.append(String(paramName))
Expand All @@ -122,13 +121,11 @@ public class SDJWTService {
}
}
}
if let inputDescriptors = presentationDefinition.inputDescriptors {
for inputDescriptor in inputDescriptors {
if let inputDescriptor = inputDescriptor {
if inputDescriptor.constraints?.limitDisclosure == nil {
return issuedJwt.isEmpty ? nil : issuedJwt
} else {
var verificationHandler : eudiWalletOidcIos.VerificationService?
let keyHandler = CryptoKitHandler()
verificationHandler = eudiWalletOidcIos.VerificationService(keyhandler: keyHandler)
let updatedDescriptor = verificationHandler?.updatePath(in: inputDescriptor)
var processedCredentials: [String] = []
Expand All @@ -138,10 +135,8 @@ public class SDJWTService {
credentialList.append(credential)

var credentialFormat: String = ""
if let format = presentationDefinition.format ?? inputDescriptor.format {
for (key, value) in format {
credentialFormat = key
}
if let format = format {
credentialFormat = format
}
if credentialFormat == "mso_mdoc" {
tempCredentialList = credentialList
Expand Down Expand Up @@ -193,7 +188,6 @@ public class SDJWTService {
print("error")
}
}
}
}
return issuedJwt.isEmpty ? nil : issuedJwt
}
Expand Down Expand Up @@ -328,3 +322,4 @@ public class SDJWTService {
return String(first)
}
}

Loading

0 comments on commit e04bca8

Please sign in to comment.