From a557403f199fa262773ab7ebc05159fe5b33a973 Mon Sep 17 00:00:00 2001 From: Taylor Dawson Date: Tue, 12 Nov 2024 10:00:19 -0800 Subject: [PATCH] Remove authKeyManager --- Package.swift | 7 ------- Tests/TurnkeySDKTests/TurnkeySDKTests.swift | 16 ++++++++-------- .../TurnkeyiOSExample/AccountManager.swift | 19 ++++++++++--------- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/Package.swift b/Package.swift index fb72a36..cd036df 100644 --- a/Package.swift +++ b/Package.swift @@ -64,12 +64,5 @@ let package = Package( .product(name: "Web3PromiseKit", package: "Web3.swift"), ] ), - // Empty target that builds the DocC catalog at /SwiftDocCPluginDocumentation/SwiftDocCPlugin.docc. - // The SwiftDocCPlugin catalog includes high-level, user-facing documentation about using - // the Swift-DocC plugin from the command-line. - .target( - name: "TurnkeySDKDocumentation", - path: "Sources/TurnkeySDKDocumentation" - ) ] ) diff --git a/Tests/TurnkeySDKTests/TurnkeySDKTests.swift b/Tests/TurnkeySDKTests/TurnkeySDKTests.swift index 708b411..10f8ff5 100644 --- a/Tests/TurnkeySDKTests/TurnkeySDKTests.swift +++ b/Tests/TurnkeySDKTests/TurnkeySDKTests.swift @@ -171,16 +171,16 @@ final class TurnkeySDKTests: XCTestCase { // Simplified validation that focuses on the essential fields XCTAssertNotNil(activityResponse.activity) XCTAssertEqual(activityResponse.activity.organizationId, organizationId) - + // Validate the result if present if let result = activityResponse.activity.result.createSubOrganizationResultV7 { - XCTAssertNotNil(result.subOrganizationId) - print("Created sub-organization: \(result.subOrganizationId)") - - if let rootUserIds = result.rootUserIds { - XCTAssertEqual(rootUserIds.count, rootUsers.count) - print("Created root users: \(rootUserIds)") - } + XCTAssertNotNil(result.subOrganizationId) + print("Created sub-organization: \(result.subOrganizationId)") + + if let rootUserIds = result.rootUserIds { + XCTAssertEqual(rootUserIds.count, rootUsers.count) + print("Created root users: \(rootUserIds)") + } } } case let .undocumented(statusCode, undocumentedPayload): diff --git a/example/TurnkeyiOSExample/TurnkeyiOSExample/AccountManager.swift b/example/TurnkeyiOSExample/TurnkeyiOSExample/AccountManager.swift index 2fd3424..c5ae285 100644 --- a/example/TurnkeyiOSExample/TurnkeyiOSExample/AccountManager.swift +++ b/example/TurnkeyiOSExample/TurnkeyiOSExample/AccountManager.swift @@ -30,14 +30,12 @@ class AccountManager: NSObject, ASAuthorizationControllerPresentationContextProv var authenticationAnchor: ASPresentationAnchor? var isPerformingModalRequest = false private var passkeyRegistration: PasskeyManager? - private let authKeyManager: AuthKeyManager private var currentEmail: String? private var modelContext: ModelContext { return AppDelegate.userModelContext } override init() { - authKeyManager = AuthKeyManager(domain: domain) super.init() // Add observers for passkey registration notifications NotificationCenter.default.addObserver( @@ -105,6 +103,12 @@ class AccountManager: NSObject, ASAuthorizationControllerPresentationContextProv isPerformingModalRequest = true } + /// A closure that verifies an encrypted bundle. + /// This closure is set when the `emailAuth` method is called and is used to verify + /// the encrypted bundle received during the email authentication process. + /// It takes a `String` representing the encrypted bundle and returns an `AuthResult` asynchronously. + private var verifyClosure: ((String) async throws -> AuthResult)? + func signInEmailAuth(email: String, anchor: ASPresentationAnchor) async { // For email auth we need to proxy the request to a backend that can stamp it let proxyURL = "http://localhost:3000/api/email-auth" @@ -112,21 +116,18 @@ class AccountManager: NSObject, ASAuthorizationControllerPresentationContextProv let turnkeyClient = TurnkeyClient(proxyURL: proxyURL) do { - let publicKey = try authKeyManager.createKeyPair() - - var targetPublicKey = Data([0x04]) - let rawRepresentation = publicKey.rawRepresentation - targetPublicKey.append(rawRepresentation) - let output = try await turnkeyClient.emailAuth( + let (output, verify) = try await turnkeyClient.emailAuth( organizationId: parentOrgId, email: email, - targetPublicKey: targetPublicKey.map { String(format: "%02x", $0) }.joined(), apiKeyName: "test-api-key-swift-sdk", expirationSeconds: "3600", emailCustomization: Components.Schemas.EmailCustomizationParams() ) + // Store the verify closure for later use + self.verifyClosure = verify + // Assert the response switch output { case let .ok(response):