no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / remote / marionette / webauthn.sys.mjs
blobc52bf6cb5c887a8e23e4d547efed63ee171fdf8a
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
7 const lazy = {};
9 XPCOMUtils.defineLazyServiceGetter(
10   lazy,
11   "webauthnService",
12   "@mozilla.org/webauthn/service;1",
13   "nsIWebAuthnService"
16 /** @namespace */
17 export const webauthn = {};
19 /**
20  * Add a virtual authenticator.
21  *
22  * @param {string} protocol one of "ctap1/u2f", "ctap2", "ctap2_1"
23  * @param {string} transport one of "usb", "nfc", "ble", "smart-card",
24  *                 "hybrid", "internal"
25  * @param {boolean} hasResidentKey
26  * @param {boolean} hasUserVerification
27  * @param {boolean} isUserConsenting
28  * @param {boolean} isUserVerified
29  * @returns {id} the id of the added authenticator
30  */
31 webauthn.addVirtualAuthenticator = function (
32   protocol,
33   transport,
34   hasResidentKey,
35   hasUserVerification,
36   isUserConsenting,
37   isUserVerified
38 ) {
39   return lazy.webauthnService.addVirtualAuthenticator(
40     protocol,
41     transport,
42     hasResidentKey,
43     hasUserVerification,
44     isUserConsenting,
45     isUserVerified
46   );
49 /**
50  * Removes a virtual authenticator.
51  *
52  * @param {id} authenticatorId the id of the virtual authenticator
53  */
54 webauthn.removeVirtualAuthenticator = function (authenticatorId) {
55   lazy.webauthnService.removeVirtualAuthenticator(authenticatorId);
58 /**
59  * Adds a credential to a previously-added virtual authenticator.
60  *
61  * @param {id} authenticatorId the id of the virtual authenticator
62  * @param {string} credentialId a probabilistically-unique byte sequence
63  *                 identifying a public key credential source and its
64  *                 authentication assertions (encoded using Base64url
65  *                 Encoding).
66  * @param {boolean} isResidentCredential if set to true, a client-side
67  *                  discoverable credential is created. If set to false, a
68  *                  server-side credential is created instead.
69  * @param {string} rpId The Relying Party ID the credential is scoped to.
70  * @param {string} privateKey An asymmetric key package containing a single
71  *                 private key per RFC5958, encoded using Base64url Encoding.
72  * @param {string} userHandle The userHandle associated to the credential
73  *                 encoded using Base64url Encoding.
74  * @param {number} signCount The initial value for a signature counter
75  *                 associated to the public key credential source.
76  */
77 webauthn.addCredential = function (
78   authenticatorId,
79   credentialId,
80   isResidentCredential,
81   rpId,
82   privateKey,
83   userHandle,
84   signCount
85 ) {
86   lazy.webauthnService.addCredential(
87     authenticatorId,
88     credentialId,
89     isResidentCredential,
90     rpId,
91     privateKey,
92     userHandle,
93     signCount
94   );
97 /**
98  * Gets all credentials from a virtual authenticator.
99  *
100  * @param {id} authenticatorId the id of the virtual authenticator
101  * @returns {object} the credentials on the authenticator
102  */
103 webauthn.getCredentials = function (authenticatorId) {
104   return lazy.webauthnService.getCredentials(authenticatorId);
108  * Removes a credential from a virtual authenticator.
110  * @param {id} authenticatorId the id of the virtual authenticator
111  * @param {string} credentialId the id of the credential
112  */
113 webauthn.removeCredential = function (authenticatorId, credentialId) {
114   lazy.webauthnService.removeCredential(authenticatorId, credentialId);
118  * Removes all credentials from a virtual authenticator.
120  * @param {id} authenticatorId the id of the virtual authenticator
121  */
122 webauthn.removeAllCredentials = function (authenticatorId) {
123   lazy.webauthnService.removeAllCredentials(authenticatorId);
127  * Sets the "isUserVerified" bit on a virtual authenticator.
129  * @param {id} authenticatorId the id of the virtual authenticator
130  * @param {bool} isUserVerified the value to set the "isUserVerified" bit to
131  */
132 webauthn.setUserVerified = function (authenticatorId, isUserVerified) {
133   lazy.webauthnService.setUserVerified(authenticatorId, isUserVerified);