Skip to content

Commit

Permalink
Fix #48: Updated DID registry URL
Browse files Browse the repository at this point in the history
  • Loading branch information
josmilan committed Sep 17, 2024
1 parent b632d5f commit 3f4a52a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,46 @@ class SignatureValidator {
static func processJWKforEBSI(did: String?) async -> [String: Any]{
guard let did = did else { return [:]}
let ebsiEndPoint = "https://api-conformance.ebsi.eu/did-registry/v5/identifiers/\(did)"
let pilotEndpoint = "https://api-pilot.ebsi.eu/did-registry/v5/identifiers/\(did)"

do {
guard let url = URL(string: ebsiEndPoint) else { return [:]}
guard let url = URL(string: ebsiEndPoint) else { return [:] }
let (data, response) = try await URLSession.shared.data(from: url)
guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else { return [:]}
guard let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], let verificationMethods = jsonObject["verificationMethod"] as? [[String: Any]] else { return [:]}
for data in verificationMethods {
if let publicKeyJwk = data["publicKeyJwk"] as? [String: Any], let crv = publicKeyJwk["crv"] as? String, crv == "P-256" {
return publicKeyJwk
}
guard let httpResponse = response as? HTTPURLResponse else { return [:] }

if httpResponse.statusCode == 200 {
// Process the response from the first URL
return try processPublicKeyFromJWKList(data)
} else {
// Call the fallback URL if the status is not 200
return try await fetchJWKListFromUrl(pilotEndpoint)
}
} catch {
print("error")
print("Error fetching from primary URL: \(error)")
}
return [:]
}

private static func processPublicKeyFromJWKList(_ data: Data) throws -> [String: Any] {
guard let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let verificationMethods = jsonObject["verificationMethod"] as? [[String: Any]] else { return [:] }

for method in verificationMethods {
if let publicKeyJwk = method["publicKeyJwk"] as? [String: Any],
let crv = publicKeyJwk["crv"] as? String, crv == "P-256" {
return publicKeyJwk
}
}
return [:]
}

private static func fetchJWKListFromUrl(_ fallbackURL: String) async throws -> [String: Any] {
guard let url = URL(string: fallbackURL) else { return [:] }
let (data, response) = try await URLSession.shared.data(from: url)
guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else { return [:] }

return try processPublicKeyFromJWKList(data)
}

static func processJWKFromJwksURI2(kid: String?, jwksURI: String?) async -> [String: Any] {
guard let jwksURI = jwksURI else {return [:]}
Expand Down
4 changes: 1 addition & 3 deletions Sources/eudiWalletOidcIos/Service/IssueServiceProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@ protocol IssueServiceProtocol {
- credentialEndpointUrlString: The URL string of the credential endpoint.
- c_nonce: The nonce value for the credential request.
- accessToken: The access token for authentication.

- Returns: A `CredentialResponse` object if the request is successful, otherwise `nil`.
*/
func processCredentialRequest(did: String, secureKey: SecureKeyData, nonce: String, credentialOffer: CredentialOffer, issuerConfig: IssuerWellKnownConfiguration, accessToken: String, format: String) async -> CredentialResponse?

// Processes a deferred credential request to obtain the credential response in deffered manner.

/** - Parameters
- acceptanceToken - token which we got from credential request
- deferredCredentialEndPoint - end point to call the deferred credential
Expand All @@ -76,6 +74,6 @@ protocol IssueServiceProtocol {

func getCryptoFromIssuerConfig(issuerConfig: IssuerWellKnownConfiguration?, type: String?) -> [String]?

func etCredentialDisplayFromIssuerConfig(issuerConfig: IssuerWellKnownConfiguration?, type: String?) -> Display?
func getCredentialDisplayFromIssuerConfig(issuerConfig: IssuerWellKnownConfiguration?, type: String?) -> Display?

}

0 comments on commit 3f4a52a

Please sign in to comment.