From d4559bb3d3912855ad1084e8dfaeefb5d71a4e21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20C=C3=A1ceres?= Date: Thu, 23 Nov 2023 10:07:00 +1100 Subject: [PATCH 1/2] Editorial: small cleanup of examples Use async/await in both examples. Use nullish coalescing. --- spec.bs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/spec.bs b/spec.bs index 42c56b3..dd20b1a 100644 --- a/spec.bs +++ b/spec.bs @@ -269,7 +269,8 @@ an issuing bank during a checkout by the user on some merchant. 1. The verification completes; the bank iframe closes and the merchant finishes the checkout process for the user. -Sample code for registering the user in this way follows: +Sample code for registering the user in this way follows. Note that the example code +presumes access to async/await, for easier to read promise handling.
 if (!window.PublicKeyCredential) { /* Client not capable. Handle error. */ }
@@ -330,12 +331,12 @@ const publicKey = {
 };
 
 // Note: The following call will cause the authenticator to display UI.
-navigator.credentials.create({ publicKey })
-  .then(function (newCredentialInfo) {
-    // Send new credential info to server for verification and registration.
-  }).catch(function (err) {
-    // No acceptable authenticator or user refused consent. Handle appropriately.
-  });
+try {
+  const newCredentialInfo = await navigator.credentials.create({ publicKey });
+  // Send new credential info to server for verification and registration.
+} catch(err) {
+  // No acceptable authenticator or user refused consent. Handle appropriately.
+}
 
@@ -370,16 +371,14 @@ Payment Confirmation. the transaction and the merchant finishes the checkout process for the user. The sample code for authenticating the user follows. Note that the example code -presumes access to await/async, for easier to read promise handling. +presumes access to async/await, for easier to read promise handling.
 /* isSecurePaymentConfirmationAvailable indicates whether the browser */
 /* supports SPC. It does not indicate whether the user has a credential */
 /* ready to go on this device. */
 const spcAvailable =
-  PaymentRequest &&
-  PaymentRequest.isSecurePaymentConfirmationAvailable &&
-  await PaymentRequest.isSecurePaymentConfirmationAvailable();
+  await PaymentRequest?.isSecurePaymentConfirmationAvailable()
 if (!spcAvailable) {
   /* Browser does not support SPC; merchant should fallback to traditional flows. */
 }

From 2b6c390ce2e31b464e90d5453b1d62188b583993 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marcos=20C=C3=A1ceres?= 
Date: Thu, 23 Nov 2023 10:07:53 +1100
Subject: [PATCH 2/2] Update spec.bs

---
 spec.bs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/spec.bs b/spec.bs
index dd20b1a..2823cf4 100644
--- a/spec.bs
+++ b/spec.bs
@@ -378,7 +378,7 @@ presumes access to async/await, for easier to read promise handling.
 /* supports SPC. It does not indicate whether the user has a credential */
 /* ready to go on this device. */
 const spcAvailable =
-  await PaymentRequest?.isSecurePaymentConfirmationAvailable()
+  await PaymentRequest?.isSecurePaymentConfirmationAvailable();
 if (!spcAvailable) {
   /* Browser does not support SPC; merchant should fallback to traditional flows. */
 }