Skip to content

Commit

Permalink
update presentation definition model (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirahsapong authored Mar 25, 2024
1 parent 1d819dd commit 3fac8cc
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
21 changes: 20 additions & 1 deletion Sources/Web5/Credentials/PresentationExchange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,39 @@ public struct CredentialSchema: Codable {
}

public struct PresentationDefinitionV2: Codable, Equatable {
public let id: String
public let name: String?
public let purpose: String?
public let format: AnyCodable?
public let submissionRequirements: [AnyCodable]?
public let inputDescriptors: [InputDescriptorV2]

enum CodingKeys: String, CodingKey {
case id
case name
case purpose
case format
case submissionRequirements = "submission_requirements"
case inputDescriptors = "input_descriptors"
}

}

public struct InputDescriptorV2: Codable, Hashable {
public let id: String
public let name: String?
public let purpose: String?
public let format: AnyCodable?
public let constraints: ConstraintsV2
}

public struct ConstraintsV2: Codable, Hashable {
public let fields: [FieldV2]?
public let limitDisclosure: Optionality?

enum CodingKeys: String, CodingKey {
case fields
case limitDisclosure = "limit_disclosure"
}
}

public struct FieldV2: Codable, Hashable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class Web5TestVectorsPresentationExchange: XCTestCase {
/// Register each of the mock network responses
try vector.input.mocks().forEach { $0.register() }

/// Resolve each input didURI, make sure it matches output
/// Select valid credentials from each of the inputs, make sure it matches output
let result = try PresentationExchange.selectCredentials(vcJWTs: vector.input.credentialJwts, presentationDefinition: vector.input.presentationDefinition)
XCTAssertEqual(result.sorted(), vector.output!.selectedCredentials.sorted())
expectation.fulfill()
Expand Down
40 changes: 34 additions & 6 deletions Tests/Web5Tests/Credentials/PresentationExchangeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class PresentationExchangeTests: XCTestCase {
"""

let inputDescriptor = InputDescriptorV2(
id: "1234567890_a",
name: nil,
purpose: nil,
format: nil,
constraints: ConstraintsV2(
fields: [
FieldV2(
Expand All @@ -27,11 +31,16 @@ class PresentationExchangeTests: XCTestCase {
path: ["$.issuer"],
filter: ["type":"string", "const": "did:key:zQ3shNLt1aMWPbWRGa8VoeEbJofJ7xJe4FCPpDKxq1NZygpiy"]
)
]
],
limitDisclosure: nil
)
)

let inputDescriptor2 = InputDescriptorV2(
id: "1234567890_b",
name: nil,
purpose: nil,
format: nil,
constraints: ConstraintsV2(
fields: [
FieldV2(
Expand All @@ -42,11 +51,16 @@ class PresentationExchangeTests: XCTestCase {
path: ["$.credentialSubject.localStreet"],
filter: ["type":"string", "const": "low"]
),
]
],
limitDisclosure: nil
)
)

let inputDescriptor3 = InputDescriptorV2(
id: "1234567890_c",
name: nil,
purpose: nil,
format: nil,
constraints: ConstraintsV2(
fields: [
FieldV2(
Expand All @@ -57,14 +71,18 @@ class PresentationExchangeTests: XCTestCase {
path: ["$.credentialSubject.localRespect"],
filter: ["type":"string", "const": "high"]
),
]
],
limitDisclosure: nil
)
)

//select_credentials - web5-spec select_credentials -> Web5TestVectors folder


func test_select_oneOfTwoCorrectCredentials() throws {
let pd = PresentationDefinitionV2(
id: "1234567890_d",
name: nil,
purpose: nil,
format: nil,
submissionRequirements: nil,
inputDescriptors: [
inputDescriptor, inputDescriptor2
]
Expand All @@ -76,6 +94,11 @@ class PresentationExchangeTests: XCTestCase {

func test_throw_zeroCorrectCredentials() throws {
let pd = PresentationDefinitionV2(
id: "1234567890_e",
name: nil,
purpose: nil,
format: nil,
submissionRequirements: nil,
inputDescriptors: [
inputDescriptor, inputDescriptor2
]
Expand All @@ -85,6 +108,11 @@ class PresentationExchangeTests: XCTestCase {

func test_select_twoOfTwoCorrectCredentials() throws {
let pd = PresentationDefinitionV2(
id: "1234567890_f",
name: nil,
purpose: nil,
format: nil,
submissionRequirements: nil,
inputDescriptors: [
inputDescriptor3
]
Expand Down

0 comments on commit 3fac8cc

Please sign in to comment.