Skip to content

Commit

Permalink
Merge pull request #37 from moratori/bugs/disclosures-parsing
Browse files Browse the repository at this point in the history
Fixed a bug related to parsing Disclosure.
  • Loading branch information
ryosuke-wakaba authored Nov 21, 2024
2 parents f7a0260 + f94a63d commit a9d6b53
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tw2023_wallet/Services/OID/PresentationExchange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ struct PresentationDefinition: Codable {
func matchSdJwtVcToRequirement(sdJwt: String) -> (
InputDescriptor, [DisclosureWithOptionality]
)? {
let parts = sdJwt.split(separator: "~").map(String.init)
let newList = parts.count > 2 ? Array(parts.dropFirst().dropLast()) : []
guard let sdJwtParts = try? SDJwtUtil.divideSDJwt(sdJwt: sdJwt) else {
return nil
}

// [Disclosure]
let allDisclosures = decodeDisclosureFunction(newList)
let allDisclosures = decodeDisclosureFunction(sdJwtParts.disclosures)
let sourcePayload = Dictionary(
uniqueKeysWithValues: allDisclosures.compactMap { disclosure in
if let key = disclosure.key, let value = disclosure.value {
Expand Down
40 changes: 40 additions & 0 deletions tw2023_walletTests/AuthorizationRquestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,46 @@ final class AuthorizationRquestTests: XCTestCase {
}
}
}

func testPresentationDefinitionMatchSdJwt() {
let configuration = URLSessionConfiguration.ephemeral
configuration.protocolClasses = [MockURLProtocol.self]
let mockSession = URLSession(configuration: configuration)

let testURL = URL(string: "https://example.com/presentation_definition.json")!
guard
let url = Bundle.main.url(
forResource: "presentation_definition", withExtension: "json"),
let mockData = try? Data(contentsOf: url)
else {
XCTFail("Cannot read presentation_definition.json")
return
}
let response = HTTPURLResponse(
url: url, statusCode: 200, httpVersion: nil, headerFields: nil)
MockURLProtocol.mockResponses[testURL.absoluteString] = (mockData, response)

let authorizationRequest = AuthorizationRequestPayloadImpl(
presentationDefinition: nil
)
let requestObject = RequestObjectPayloadImpl(
presentationDefinitionUri: testURL.absoluteString
)

runAsyncTest {
do {
let pdOptional = try await processPresentationDefinition(
authorizationRequest, requestObject, using: mockSession)
let pd = try XCTUnwrap(pdOptional, "PresentationDefinition should not be nil.")
let sdJwt = "eyJ0eXAiOiJzZCtqd3QiLCJhbGciOiJFUzI1NiJ9.eyJfc2QiOlsiOWhnWm5VbGEyT1JhTHB3Wkp6T0pBTUZfVUd2dzVOekIwTEdmU1VaNTN6cyJdLCJfc2RfYWxnIjoiU0hBLTI1NiJ9.nzsiKRK39ijCaw0oD9nmhrB41HnZj_CiShckWZAVRW3tCDTm3vrJHyoVj4F7_2mx2aMvbT4iAekDGGtsXyhdvw~WyJmZWE3MTcwYTc3OGRiNzk1IiwiaXNfb2xkZXJfdGhhbl8xMyIsdHJ1ZV0~"
XCTAssertNotNil(pd.matchSdJwtVcToRequirement(sdJwt: sdJwt))
XCTAssertEqual(pd.id, "12345")
}
catch {
XCTFail("Request should not fail. \(error)")
}
}
}

func testPresentationDefinitionFromQueryParameter() {
let configuration = URLSessionConfiguration.ephemeral
Expand Down

0 comments on commit a9d6b53

Please sign in to comment.