|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the WebAuthn Swift open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2024 the WebAuthn Swift project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of WebAuthn Swift project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +@preconcurrency import Crypto |
| 16 | +import SwiftCBOR |
| 17 | + |
| 18 | +public struct AttestationRegistrationRequest: Sendable { |
| 19 | + var options: PublicKeyCredentialCreationOptions |
| 20 | + var publicKeyCredentialParameters: [PublicKeyCredentialParameters] |
| 21 | + var clientDataHash: SHA256Digest |
| 22 | + var attemptRegistration: Callback |
| 23 | + |
| 24 | + init( |
| 25 | + options: PublicKeyCredentialCreationOptions, |
| 26 | + publicKeyCredentialParameters: [PublicKeyCredentialParameters], |
| 27 | + clientDataHash: SHA256Digest, |
| 28 | + attemptRegistration: @Sendable @escaping (_ attestationObject: AttestationObject) async throws -> () |
| 29 | + ) { |
| 30 | + self.options = options |
| 31 | + self.publicKeyCredentialParameters = publicKeyCredentialParameters |
| 32 | + self.clientDataHash = clientDataHash |
| 33 | + self.attemptRegistration = Callback(callback: attemptRegistration) |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +extension AttestationRegistrationRequest { |
| 38 | + public struct Callback: Sendable { |
| 39 | + /// The internal callback the attestation should call. |
| 40 | + var callback: @Sendable (_ attestationObject: AttestationObject) async throws -> () |
| 41 | + |
| 42 | + /// Generate an attestation object for registration and submit it. |
| 43 | + /// |
| 44 | + /// Authenticators should call this to submit a successful registration and cancel any other pending authenticators. |
| 45 | + /// |
| 46 | + /// - SeeAlso: https://w3c.github.io/webauthn/#sctn-generating-an-attestation-object |
| 47 | + public func submitAttestationObject( |
| 48 | + attestationFormat: AttestationFormat, |
| 49 | + authenticatorData: AuthenticatorData, |
| 50 | + attestationStatement: CBOR |
| 51 | + ) async throws { |
| 52 | + try await callback(AttestationObject( |
| 53 | + authenticatorData: authenticatorData, |
| 54 | + format: attestationFormat, |
| 55 | + attestationStatement: attestationStatement |
| 56 | + )) |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments