This commit is contained in:
sydneymorton 2020-10-01 17:44:35 -07:00
Родитель a6e170ce3f
Коммит f5fbcaee99
3 изменённых файлов: 54 добавлений и 1 удалений

Просмотреть файл

@ -10,7 +10,7 @@ enum PresentationResponseError: Error {
public struct PresentationResponseContainer {
let request: PresentationRequest
let expiryInSeconds: Int
let audience: String?
public let audience: String?
public var requestedIdTokenMap: RequestedIdTokenMap = [:]
public var requestedSelfAttestedClaimMap: RequestedSelfAttestedClaimMap = [:]
public var requestVCMap: RequestedVerifiableCredentialMap = [:]

Просмотреть файл

@ -15,6 +15,7 @@
550F1E6625116CD6009AF467 /* TestData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 550F1E6525116CD6009AF467 /* TestData.swift */; };
550F1E6825116E86009AF467 /* MockTokenSigner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 550F1E6725116E86009AF467 /* MockTokenSigner.swift */; };
550F1E6A25125BC6009AF467 /* MockIssuanceResponseFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 550F1E6925125BC6009AF467 /* MockIssuanceResponseFormatter.swift */; };
555CE0932526AD0400C1C938 /* PresentationUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 555CE0922526AD0400C1C938 /* PresentationUseCase.swift */; };
922D7E7A2525248900E4C8B5 /* VCRepository.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 922D7E792525248900E4C8B5 /* VCRepository.framework */; };
922D7E7F2525264400E4C8B5 /* PromiseKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 92B9682425240AE600F64AB0 /* PromiseKit.framework */; };
922D7E802525264400E4C8B5 /* PromiseKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 92B9682425240AE600F64AB0 /* PromiseKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@ -56,6 +57,7 @@
550F1E6525116CD6009AF467 /* TestData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestData.swift; sourceTree = "<group>"; };
550F1E6725116E86009AF467 /* MockTokenSigner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockTokenSigner.swift; sourceTree = "<group>"; };
550F1E6925125BC6009AF467 /* MockIssuanceResponseFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockIssuanceResponseFormatter.swift; sourceTree = "<group>"; };
555CE0922526AD0400C1C938 /* PresentationUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresentationUseCase.swift; sourceTree = "<group>"; };
922D7E792525248900E4C8B5 /* VCRepository.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = VCRepository.framework; sourceTree = BUILT_PRODUCTS_DIR; };
92B9681C25240AB800F64AB0 /* PromiseKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = PromiseKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
92B9682025240ADD00F64AB0 /* PMKFoundation.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = PMKFoundation.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@ -106,6 +108,7 @@
isa = PBXGroup;
children = (
550F1E532510195A009AF467 /* IssuanceUseCase.swift */,
555CE0922526AD0400C1C938 /* PresentationUseCase.swift */,
550F1E3825101758009AF467 /* VCUseCase.h */,
550F1E3925101758009AF467 /* Info.plist */,
);
@ -256,6 +259,7 @@
buildActionMask = 2147483647;
files = (
550F1E542510195A009AF467 /* IssuanceUseCase.swift in Sources */,
555CE0932526AD0400C1C938 /* PresentationUseCase.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

Просмотреть файл

@ -0,0 +1,49 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import PromiseKit
import VCRepository
import VCEntities
public class PresentationUseCase {
let masterIdentifier: MockIdentifier = MockIdentifier()
let formatter: PresentationResponseFormatter
let repo: PresentationRepository
public init() {
self.formatter = PresentationResponseFormatter()
self.repo = PresentationRepository()
}
init(formatter: PresentationResponseFormatter,
repo: PresentationRepository) {
self.formatter = formatter
self.repo = repo
}
public func getRequest(usingUrl url: String) -> Promise<PresentationRequest> {
return self.repo.getRequest(withUrl: url)
}
public func send(response: PresentationResponseContainer, identifier: MockIdentifier) -> Promise<String?> {
return firstly {
self.formatPresentationResponse(response: response, identifier: identifier)
}.then { signedToken in
self.repo.sendResponse(usingUrl: response.audience!, withBody: signedToken)
}
}
private func formatPresentationResponse(response: PresentationResponseContainer, identifier: MockIdentifier) -> Promise<PresentationResponse> {
return Promise { seal in
do {
seal.fulfill(try self.formatter.format(response: response, usingIdentifier: identifier))
} catch {
seal.reject(error)
}
}
}
}