summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'packages/browser/src/helpers')
-rw-r--r--packages/browser/src/helpers/toAuthenticatorAttachment.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/packages/browser/src/helpers/toAuthenticatorAttachment.ts b/packages/browser/src/helpers/toAuthenticatorAttachment.ts
new file mode 100644
index 0000000..7a2aca0
--- /dev/null
+++ b/packages/browser/src/helpers/toAuthenticatorAttachment.ts
@@ -0,0 +1,18 @@
+import { AuthenticatorAttachment } from '@simplewebauthn/typescript-types';
+
+const attachments: AuthenticatorAttachment[] = ['cross-platform', 'platform'];
+
+/**
+ * If possible coerce a `string` value into a known `AuthenticatorAttachment`
+ */
+export function toAuthenticatorAttachment(attachment: string | null): AuthenticatorAttachment | undefined {
+ if (!attachment) {
+ return;
+ }
+
+ if (attachments.indexOf(attachment as AuthenticatorAttachment) < 0) {
+ return;
+ }
+
+ return attachment as AuthenticatorAttachment;
+}