Skip to content

Commit

Permalink
Update Requirement Classes (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
symorton authored Feb 6, 2023
1 parent 1a61d82 commit 583d77f
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 57 deletions.
16 changes: 8 additions & 8 deletions WalletLibrary/WalletLibrary.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
550E3214298B11A5004E7716 /* Requirement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 550E3213298B11A5004E7716 /* Requirement.swift */; };
550E3217298B1236004E7716 /* RequesterStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 550E3216298B1236004E7716 /* RequesterStyle.swift */; };
552E509B293E6AB200868F47 /* WalletLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 552E5092293E6AB200868F47 /* WalletLibrary.framework */; };
552E50A0293E6AB200868F47 /* VerifiedIdFlowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 552E509F293E6AB200868F47 /* VerifiedIdFlowTests.swift */; };
552E50A0293E6AB200868F47 /* VerifiedIdClientTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 552E509F293E6AB200868F47 /* VerifiedIdClientTests.swift */; };
552E50A1293E6AB200868F47 /* WalletLibrary.h in Headers */ = {isa = PBXBuildFile; fileRef = 552E5095293E6AB200868F47 /* WalletLibrary.h */; settings = {ATTRIBUTES = (Public, ); }; };
5534E5972948B8C2005D0765 /* VCServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 55E336E7293FCE4F00CD2ED7 /* VCServices.framework */; platformFilter = ios; };
5534E5982948B8C2005D0765 /* VCServices.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 55E336E7293FCE4F00CD2ED7 /* VCServices.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand All @@ -36,7 +36,7 @@
55E336D1293FA6F400CD2ED7 /* VerifiedIdRequirement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E336D0293FA6F400CD2ED7 /* VerifiedIdRequirement.swift */; };
55E336D4293FA75300CD2ED7 /* VerifiedId.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E336D3293FA75300CD2ED7 /* VerifiedId.swift */; };
55E336D6293FA78C00CD2ED7 /* VerifiedIdClaim.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E336D5293FA78C00CD2ED7 /* VerifiedIdClaim.swift */; };
55E336D8293FCE0500CD2ED7 /* CredentialIssuanceParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E336D7293FCE0500CD2ED7 /* CredentialIssuanceParams.swift */; };
55E336D8293FCE0500CD2ED7 /* IssuanceOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E336D7293FCE0500CD2ED7 /* IssuanceOptions.swift */; };
55E33708293FD25900CD2ED7 /* AccessTokenRequirement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E33707293FD25900CD2ED7 /* AccessTokenRequirement.swift */; };
55E3370A293FD3E000CD2ED7 /* IdTokenRequirement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E33709293FD3E000CD2ED7 /* IdTokenRequirement.swift */; };
55E3370C293FD61E00CD2ED7 /* SelfAttestedClaimRequirement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E3370B293FD61E00CD2ED7 /* SelfAttestedClaimRequirement.swift */; };
Expand Down Expand Up @@ -235,7 +235,7 @@
552E5092293E6AB200868F47 /* WalletLibrary.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = WalletLibrary.framework; sourceTree = BUILT_PRODUCTS_DIR; };
552E5095293E6AB200868F47 /* WalletLibrary.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WalletLibrary.h; sourceTree = "<group>"; };
552E509A293E6AB200868F47 /* WalletLibraryTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = WalletLibraryTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
552E509F293E6AB200868F47 /* VerifiedIdFlowTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerifiedIdFlowTests.swift; sourceTree = "<group>"; };
552E509F293E6AB200868F47 /* VerifiedIdClientTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerifiedIdClientTests.swift; sourceTree = "<group>"; };
552E50BD293E71D600868F47 /* VCEntities.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = VCEntities.xcodeproj; path = VCEntities/VCEntities.xcodeproj; sourceTree = "<group>"; };
552E51AE293E71D700868F47 /* VCServices.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = VCServices.xcodeproj; path = VCServices/VCServices.xcodeproj; sourceTree = "<group>"; };
552E51D8293E71D700868F47 /* VCToken.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = VCToken.xcodeproj; path = VCToken/VCToken.xcodeproj; sourceTree = "<group>"; };
Expand All @@ -257,7 +257,7 @@
55E336D0293FA6F400CD2ED7 /* VerifiedIdRequirement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerifiedIdRequirement.swift; sourceTree = "<group>"; };
55E336D3293FA75300CD2ED7 /* VerifiedId.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerifiedId.swift; sourceTree = "<group>"; };
55E336D5293FA78C00CD2ED7 /* VerifiedIdClaim.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VerifiedIdClaim.swift; sourceTree = "<group>"; };
55E336D7293FCE0500CD2ED7 /* CredentialIssuanceParams.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CredentialIssuanceParams.swift; sourceTree = "<group>"; };
55E336D7293FCE0500CD2ED7 /* IssuanceOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssuanceOptions.swift; sourceTree = "<group>"; };
55E33707293FD25900CD2ED7 /* AccessTokenRequirement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccessTokenRequirement.swift; sourceTree = "<group>"; };
55E33709293FD3E000CD2ED7 /* IdTokenRequirement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdTokenRequirement.swift; sourceTree = "<group>"; };
55E3370B293FD61E00CD2ED7 /* SelfAttestedClaimRequirement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelfAttestedClaimRequirement.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -342,7 +342,7 @@
children = (
5534E67C294A392F005D0765 /* Extensions */,
55E3376929478C3300CD2ED7 /* Utilities */,
552E509F293E6AB200868F47 /* VerifiedIdFlowTests.swift */,
552E509F293E6AB200868F47 /* VerifiedIdClientTests.swift */,
);
path = WalletLibraryTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -488,7 +488,7 @@
children = (
55E33707293FD25900CD2ED7 /* AccessTokenRequirement.swift */,
55E3379D2948B4B000CD2ED7 /* CredentialFormat.swift */,
55E336D7293FCE0500CD2ED7 /* CredentialIssuanceParams.swift */,
55E336D7293FCE0500CD2ED7 /* IssuanceOptions.swift */,
55E33709293FD3E000CD2ED7 /* IdTokenRequirement.swift */,
55E337B32948B4B000CD2ED7 /* PinRequirement.swift */,
55E3370B293FD61E00CD2ED7 /* SelfAttestedClaimRequirement.swift */,
Expand Down Expand Up @@ -938,7 +938,7 @@
5534E667294A0B6C005D0765 /* Mappable.swift in Sources */,
55E3370E293FD84700CD2ED7 /* IssuanceRequest.swift in Sources */,
55E3370A293FD3E000CD2ED7 /* IdTokenRequirement.swift in Sources */,
55E336D8293FCE0500CD2ED7 /* CredentialIssuanceParams.swift in Sources */,
55E336D8293FCE0500CD2ED7 /* IssuanceOptions.swift in Sources */,
550E320C298B0F30004E7716 /* WalletLibraryLogConsumer.swift in Sources */,
550E3217298B1236004E7716 /* RequesterStyle.swift in Sources */,
55E336D1293FA6F400CD2ED7 /* VerifiedIdRequirement.swift in Sources */,
Expand Down Expand Up @@ -974,7 +974,7 @@
55E3376B29478C5000CD2ED7 /* AsyncWrapperTests.swift in Sources */,
5534E6AD294AAFA6005D0765 /* PresentationDescriptorMappingTests.swift in Sources */,
5534E68C294A8B8F005D0765 /* AccessTokenDescriptorMappingTests.swift in Sources */,
552E50A0293E6AB200868F47 /* VerifiedIdFlowTests.swift in Sources */,
552E50A0293E6AB200868F47 /* VerifiedIdClientTests.swift in Sources */,
5534E688294A5F16005D0765 /* IdTokenDescriptorMappingTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ extension VCEntities.IdTokenDescriptor: Mappable {
configuration: configuration,
clientId: clientID,
redirectUri: redirectUri,
scope: scope,
nonce: nil)
scope: scope)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ extension VCEntities.PresentationDescriptor: Mappable {

let acceptedIssuers = issuers?.compactMap { $0.iss } ?? []

var issuanceParams: CredentialIssuanceParams? = nil
var issuanceOptions: IssuanceOptions? = nil
if let contracts = contracts,
!contracts.isEmpty {
issuanceParams = CredentialIssuanceParams(acceptedIssuers: acceptedIssuers,
credentialIssuerMetadata: contracts)
issuanceOptions = IssuanceOptions(acceptedIssuers: acceptedIssuers,
credentialIssuerMetadata: contracts)
}

return VerifiedIdRequirement(encrypted: encrypted ?? false,
required: presentationRequired ?? false,
types: [credentialType],
acceptedIssuers: acceptedIssuers,
purpose: nil,
credentialIssuanceParams: issuanceParams)
issuanceOptions: issuanceOptions)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
/**
* Information to describe an access token required for a Verified Id issuance flow.
*/
public struct AccessTokenRequirement: Equatable {

public class AccessTokenRequirement: Requirement {
/// If the requirement should be encrypted.
let encrypted: Bool

Expand All @@ -25,5 +25,22 @@ public struct AccessTokenRequirement: Equatable {

/// The scope value used to get the access token through an authentication library.
public let scope: String

init(encrypted: Bool,
required: Bool,
configuration: String,
clientId: String?,
resourceId: String,
scope: String) {
self.encrypted = encrypted
self.required = required
self.configuration = configuration
self.clientId = clientId
self.resourceId = resourceId
self.scope = scope
}

public func validate() throws {
throw VerifiedIdClientError.TODO(message: "implement validate")
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Information to describe an id token required for a Verified Id issuance flow.
*/
public struct IdTokenRequirement: Equatable {
public class IdTokenRequirement: Requirement {

/// If the requirement should be encrypted.
let encrypted: Bool
Expand All @@ -30,5 +30,22 @@ public struct IdTokenRequirement: Equatable {
/// within the id token request through an authentication library. The nonce will be placed within
/// the id token retrieved and can be used for validation during an issuance request to an issuance service.
public internal(set) var nonce: String? = nil

init(encrypted: Bool,
required: Bool,
configuration: URL,
clientId: String,
redirectUri: String,
scope: String) {
self.encrypted = encrypted
self.required = required
self.configuration = configuration
self.clientId = clientId
self.redirectUri = redirectUri
self.scope = scope
}

public func validate() throws {
throw VerifiedIdClientError.TODO(message: "implement validate")
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
* Parameters used for an Issuance during Presentation flow
* to define information needed for the issuance of the requested Verified Id.
*/
public struct CredentialIssuanceParams: Equatable {
public struct IssuanceOptions: Equatable {

/// A list of issuers that are accepted.
public let acceptedIssuers: [String]

/// Information such as a contract URL to describe where to get contract.
public let credentialIssuerMetadata: [String]
}


Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,26 @@
/**
* Information to describe a pin that is required.
*/
public struct PinRequirement {
public class PinRequirement: Requirement {

/// If the requirement is required or not.
public let required: Bool

/// The length of the pin to display.
public let length: Int

/// The type of the pin such as alphanumeric or numeric.
public let type: String

init(required: Bool,
length: Int,
type: String) {
self.required = required
self.length = length
self.type = type
}

public func validate() throws {
throw VerifiedIdClientError.TODO(message: "implement validate")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Information to describe a self attested claim required for a Verified Id issuance flow.
*/
public struct SelfAttestedClaimRequirement: Equatable {
public class SelfAttestedClaimRequirement: Requirement {

/// If the requirement should be encrypted.
let encrypted: Bool
Expand All @@ -16,5 +16,14 @@ public struct SelfAttestedClaimRequirement: Equatable {

/// The claim requested.
public let claim: String

init(encrypted: Bool, required: Bool, claim: String) {
self.encrypted = encrypted
self.required = required
self.claim = claim
}

public func validate() throws {
throw VerifiedIdClientError.TODO(message: "implement validate")
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Information to describe Verified IDs required.
*/
public struct VerifiedIdRequirement: Equatable {
public class VerifiedIdRequirement: Requirement {

/// If requirement must be encrypted.
let encrypted: Bool
Expand All @@ -24,10 +24,28 @@ public struct VerifiedIdRequirement: Equatable {
public let purpose: String?

/// An optional property for information needed for issuance during presentation flow.
public let credentialIssuanceParams: CredentialIssuanceParams?
public let issuanceOptions: IssuanceOptions?

/// TODO: helper method that returns verified id that match the requirement from a list of verified ids.
public func getMatches(verifiedIds: [VerifiedId]) -> [VerifiedId] {
return []
}

init(encrypted: Bool,
required: Bool,
types: [String],
acceptedIssuers: [String],
purpose: String?,
issuanceOptions: IssuanceOptions?) {
self.encrypted = encrypted
self.required = required
self.types = types
self.acceptedIssuers = acceptedIssuers
self.purpose = purpose
self.issuanceOptions = issuanceOptions
}

public func validate() throws {
throw VerifiedIdClientError.TODO(message: "implement validate")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ class AccessTokenDescriptorMappingTests: XCTestCase {
func testSuccessfulMapping() throws {
let (input, expectedResult) = try setUpInput(encrypted: false, required: false)
let actualResult = try mapper.map(input)
XCTAssertEqual(actualResult, expectedResult)
assertEqual(actual: actualResult, expected: expectedResult)
}

func testMappingWithEncryptedAsTrueValue() throws {
let (input, expectedResult) = try setUpInput(encrypted: true, required: false)
let actualResult = try mapper.map(input)
XCTAssertEqual(actualResult, expectedResult)
assertEqual(actual: actualResult, expected: expectedResult)
}

func testMappingWithEncryptedAsNilValue() throws {
let (input, expectedResult) = try setUpInput(encrypted: nil, required: false)
let actualResult = try mapper.map(input)
XCTAssertEqual(actualResult, expectedResult)
assertEqual(actual: actualResult, expected: expectedResult)
}

func testMappingWithRequiredAsTrueValue() throws {
let (input, expectedResult) = try setUpInput(encrypted: false, required: true)
let actualResult = try mapper.map(input)
XCTAssertEqual(actualResult, expectedResult)
assertEqual(actual: actualResult, expected: expectedResult)
}

func testMappingWithRequiredAsNilValue() throws {
let (input, expectedResult) = try setUpInput(encrypted: false, required: nil)
let actualResult = try mapper.map(input)
XCTAssertEqual(actualResult, expectedResult)
assertEqual(actual: actualResult, expected: expectedResult)
}

func testMappingWithNoConfigurationPresentError() throws {
Expand Down Expand Up @@ -102,6 +102,15 @@ class AccessTokenDescriptorMappingTests: XCTestCase {
}
}

private func assertEqual(actual: AccessTokenRequirement, expected: AccessTokenRequirement) {
XCTAssertEqual(actual.encrypted, expected.encrypted)
XCTAssertEqual(actual.required, expected.required)
XCTAssertEqual(actual.configuration, expected.configuration)
XCTAssertEqual(actual.clientId, expected.clientId)
XCTAssertEqual(actual.resourceId, expected.resourceId)
XCTAssertEqual(actual.scope, expected.scope)
}

private func setUpInput(encrypted: Bool?,
required: Bool?) throws -> (AccessTokenDescriptor, AccessTokenRequirement) {
let input = AccessTokenDescriptor(id: expectedId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,31 @@ class IdTokenDescriptorMappingTests: XCTestCase {
func testSuccessfulMapping() throws {
let (input, expectedResult) = try setUpInput(encrypted: false, required: false)
let actualResult = try mapper.map(input)
XCTAssertEqual(actualResult, expectedResult)
assertEqual(actualResult, expectedResult)
}

func testMappingWithEncryptedAsTrueValue() throws {
let (input, expectedResult) = try setUpInput(encrypted: true, required: false)
let actualResult = try mapper.map(input)
XCTAssertEqual(actualResult, expectedResult)
assertEqual(actualResult, expectedResult)
}

func testMappingWithEncryptedAsNilValue() throws {
let (input, expectedResult) = try setUpInput(encrypted: nil, required: false)
let actualResult = try mapper.map(input)
XCTAssertEqual(actualResult, expectedResult)
assertEqual(actualResult, expectedResult)
}

func testMappingWithRequiredAsTrueValue() throws {
let (input, expectedResult) = try setUpInput(encrypted: false, required: true)
let actualResult = try mapper.map(input)
XCTAssertEqual(actualResult, expectedResult)
assertEqual(actualResult, expectedResult)
}

func testMappingWithRequiredAsNilValue() throws {
let (input, expectedResult) = try setUpInput(encrypted: false, required: nil)
let actualResult = try mapper.map(input)
XCTAssertEqual(actualResult, expectedResult)
assertEqual(actualResult, expectedResult)
}

func testMappingWithNoRedirectUrlPresentError() throws {
Expand Down Expand Up @@ -98,6 +98,16 @@ class IdTokenDescriptorMappingTests: XCTestCase {
}
}

private func assertEqual(_ actual: IdTokenRequirement, _ expected: IdTokenRequirement) {
XCTAssertEqual(actual.encrypted, expected.encrypted)
XCTAssertEqual(actual.required, expected.required)
XCTAssertEqual(actual.configuration, expected.configuration)
XCTAssertEqual(actual.clientId, expected.clientId)
XCTAssertEqual(actual.redirectUri, expected.redirectUri)
XCTAssertEqual(actual.scope, expected.scope)
XCTAssertEqual(actual.nonce, expected.nonce)
}

private func setUpInput(encrypted: Bool?, required: Bool?) throws -> (IdTokenDescriptor, IdTokenRequirement) {
let input = IdTokenDescriptor(encrypted: encrypted,
claims: [],
Expand Down
Loading

0 comments on commit 583d77f

Please sign in to comment.