1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_PublicKeyCredential_h
8 #define mozilla_dom_PublicKeyCredential_h
10 #include "js/TypeDecls.h"
11 #include "mozilla/Attributes.h"
12 #include "mozilla/dom/AuthenticatorAssertionResponse.h"
13 #include "mozilla/dom/AuthenticatorAttestationResponse.h"
14 #include "mozilla/dom/BindingDeclarations.h"
15 #include "mozilla/dom/Credential.h"
16 #include "nsCycleCollectionParticipant.h"
17 #include "nsWrapperCache.h"
19 namespace mozilla::dom
{
21 class PublicKeyCredential final
: public Credential
{
23 NS_DECL_ISUPPORTS_INHERITED
24 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(PublicKeyCredential
,
27 explicit PublicKeyCredential(nsPIDOMWindowInner
* aParent
);
30 ~PublicKeyCredential() override
;
33 virtual JSObject
* WrapObject(JSContext
* aCx
,
34 JS::Handle
<JSObject
*> aGivenProto
) override
;
36 void GetRawId(JSContext
* aCx
, JS::MutableHandle
<JSObject
*> aValue
,
39 void GetAuthenticatorAttachment(DOMString
& aAuthenticatorAttachment
);
41 already_AddRefed
<AuthenticatorResponse
> Response() const;
43 void SetRawId(const nsTArray
<uint8_t>& aBuffer
);
45 void SetAuthenticatorAttachment(
46 const Maybe
<nsString
>& aAuthenticatorAttachment
);
48 void SetAttestationResponse(
49 const RefPtr
<AuthenticatorAttestationResponse
>& aAttestationResponse
);
50 void SetAssertionResponse(
51 const RefPtr
<AuthenticatorAssertionResponse
>& aAssertionResponse
);
53 static already_AddRefed
<Promise
>
54 IsUserVerifyingPlatformAuthenticatorAvailable(GlobalObject
& aGlobal
,
57 static already_AddRefed
<Promise
> GetClientCapabilities(GlobalObject
& aGlobal
,
60 static already_AddRefed
<Promise
> IsConditionalMediationAvailable(
61 GlobalObject
& aGlobal
, ErrorResult
& aError
);
63 void GetClientExtensionResults(
64 JSContext
* cx
, AuthenticationExtensionsClientOutputs
& aResult
) const;
66 void ToJSON(JSContext
* aCx
, JS::MutableHandle
<JSObject
*> aRetval
,
69 void SetClientExtensionResultAppId(bool aResult
);
71 void SetClientExtensionResultCredPropsRk(bool aResult
);
73 void SetClientExtensionResultHmacSecret(bool aHmacCreateSecret
);
74 void InitClientExtensionResultPrf();
75 void SetClientExtensionResultPrfEnabled(bool aPrfEnabled
);
76 void SetClientExtensionResultPrfResultsFirst(
77 const nsTArray
<uint8_t>& aPrfResultsFirst
);
78 void SetClientExtensionResultPrfResultsSecond(
79 const nsTArray
<uint8_t>& aPrfResultsSecond
);
81 static void ParseCreationOptionsFromJSON(
82 GlobalObject
& aGlobal
,
83 const PublicKeyCredentialCreationOptionsJSON
& aOptions
,
84 PublicKeyCredentialCreationOptions
& aResult
, ErrorResult
& aRv
);
86 static void ParseRequestOptionsFromJSON(
87 GlobalObject
& aGlobal
,
88 const PublicKeyCredentialRequestOptionsJSON
& aOptions
,
89 PublicKeyCredentialRequestOptions
& aResult
, ErrorResult
& aRv
);
92 nsTArray
<uint8_t> mRawId
;
93 JS::Heap
<JSObject
*> mRawIdCachedObj
;
94 Maybe
<nsString
> mAuthenticatorAttachment
;
95 RefPtr
<AuthenticatorAttestationResponse
> mAttestationResponse
;
96 RefPtr
<AuthenticatorAssertionResponse
> mAssertionResponse
;
97 AuthenticationExtensionsClientOutputs mClientExtensionOutputs
;
99 // We need a reference to JSContext in order to convert nsTArray to
100 // BufferSource, so we need to store these outside mClientExtensionOutputs and
101 // defer the conversion until the GetClientExtensionResults call.
102 Maybe
<nsTArray
<uint8_t>> mPrfResultsFirst
;
103 Maybe
<nsTArray
<uint8_t>> mPrfResultsSecond
;
106 } // namespace mozilla::dom
108 #endif // mozilla_dom_PublicKeyCredential_h