diff options
author | Matthew Miller <matthew@millerti.me> | 2022-12-27 22:02:11 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-27 22:02:11 -0800 |
commit | 76c7a46b60b1093e9e71f38670175bee45512473 (patch) | |
tree | 686adb3a370e68f76541400740a0b722350d8705 /packages/browser/src/helpers/toAuthenticatorAttachment.ts | |
parent | 495c0881367ec3017553f74c3c826fb68cfd407f (diff) | |
parent | 08f7f69b221ce33b4bfa6108493fe20d0b7f93b0 (diff) |
Merge pull request #320 from MasterKale/feat/webauthn-L3-json-types
feat/webauthn-L3-json-types
Diffstat (limited to 'packages/browser/src/helpers/toAuthenticatorAttachment.ts')
-rw-r--r-- | packages/browser/src/helpers/toAuthenticatorAttachment.ts | 20 |
1 files changed, 20 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..366cf8f --- /dev/null +++ b/packages/browser/src/helpers/toAuthenticatorAttachment.ts @@ -0,0 +1,20 @@ +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; +} |