CredentialsMessenger.h [plain text]
#pragma once
#if ENABLE(WEB_AUTHN)
#include "ExceptionData.h"
#include "ExceptionOr.h"
#include <JavaScriptCore/ArrayBuffer.h>
#include <wtf/CompletionHandler.h>
#include <wtf/HashMap.h>
#include <wtf/WeakPtr.h>
namespace WebCore {
class DeferredPromise;
struct PublicKeyCredentialCreationOptions;
struct PublicKeyCredentialRequestOptions;
struct CreationReturnBundle {
CreationReturnBundle(Ref<ArrayBuffer>&& credentialId, Ref<ArrayBuffer>&& attestationObject)
: credentialId(WTFMove(credentialId))
, attestationObject(WTFMove(attestationObject))
{
}
Ref<ArrayBuffer> credentialId;
Ref<ArrayBuffer> attestationObject;
};
struct AssertionReturnBundle {
AssertionReturnBundle(Ref<ArrayBuffer>&& credentialId, Ref<ArrayBuffer>&& authenticatorData, Ref<ArrayBuffer>&& signature, Ref<ArrayBuffer>&& userHandle)
: credentialId(WTFMove(credentialId))
, authenticatorData(WTFMove(authenticatorData))
, signature(WTFMove(signature))
, userHandle(WTFMove(userHandle))
{
}
Ref<ArrayBuffer> credentialId;
Ref<ArrayBuffer> authenticatorData;
Ref<ArrayBuffer> signature;
Ref<ArrayBuffer> userHandle;
};
using CreationCompletionHandler = CompletionHandler<void(ExceptionOr<CreationReturnBundle>&&)>;
using RequestCompletionHandler = CompletionHandler<void(ExceptionOr<AssertionReturnBundle>&&)>;
using QueryCompletionHandler = CompletionHandler<void(bool)>;
class CredentialsMessenger : public CanMakeWeakPtr<CredentialsMessenger> {
WTF_MAKE_FAST_ALLOCATED;
WTF_MAKE_NONCOPYABLE(CredentialsMessenger);
public:
CredentialsMessenger() = default;
virtual void makeCredential(const Vector<uint8_t>& hash, const PublicKeyCredentialCreationOptions&, CreationCompletionHandler&&) = 0;
virtual void getAssertion(const Vector<uint8_t>& hash, const PublicKeyCredentialRequestOptions&, RequestCompletionHandler&&) = 0;
virtual void isUserVerifyingPlatformAuthenticatorAvailable(QueryCompletionHandler&&) = 0;
WEBCORE_EXPORT void exceptionReply(uint64_t messageId, const ExceptionData&);
virtual void makeCredentialReply(uint64_t messageId, const Vector<uint8_t>& credentialId, const Vector<uint8_t>& attestationObject) = 0;
virtual void getAssertionReply(uint64_t messageId, const Vector<uint8_t>& credentialId, const Vector<uint8_t>& authenticatorData, const Vector<uint8_t>& signature, const Vector<uint8_t>& userHandle) = 0;
virtual void isUserVerifyingPlatformAuthenticatorAvailableReply(uint64_t messageId, bool) = 0;
protected:
virtual ~CredentialsMessenger() = default;
WEBCORE_EXPORT uint64_t addCreationCompletionHandler(CreationCompletionHandler&&);
WEBCORE_EXPORT CreationCompletionHandler takeCreationCompletionHandler(uint64_t);
WEBCORE_EXPORT uint64_t addRequestCompletionHandler(RequestCompletionHandler&&);
WEBCORE_EXPORT RequestCompletionHandler takeRequestCompletionHandler(uint64_t);
WEBCORE_EXPORT uint64_t addQueryCompletionHandler(QueryCompletionHandler&&);
WEBCORE_EXPORT QueryCompletionHandler takeQueryCompletionHandler(uint64_t);
private:
enum CallBackClassifier : uint64_t {
Creation = 0x01,
Request = 0x02,
Query = 0x03,
};
uint64_t m_accumulatedMessageId { 1 };
HashMap<uint64_t, CreationCompletionHandler> m_pendingCreationCompletionHandlers;
HashMap<uint64_t, RequestCompletionHandler> m_pendingRequestCompletionHandlers;
HashMap<uint64_t, QueryCompletionHandler> m_pendingQueryCompletionHandlers;
};
}
#endif // ENABLE(WEB_AUTHN)