summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers/toPublicKeyCredentialDescriptor.ts
blob: 82b6ac1bc5fa82db8c0f3bef5366038644e97a77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import type { PublicKeyCredentialDescriptorJSON } from '@simplewebauthn/typescript-types';

import base64URLStringToBuffer from './base64URLStringToBuffer';

export default function toPublicKeyCredentialDescriptor(
  descriptor: PublicKeyCredentialDescriptorJSON,
): PublicKeyCredentialDescriptor {
  const { id } = descriptor;

  return {
    ...descriptor,
    id: base64URLStringToBuffer(id),
    /**
     * `descriptor.transports` is an array of our `AuthenticatorTransport` that includes newer
     * transports that TypeScript's DOM lib is ignorant of. Convince TS that our list of transports
     * are fine to pass to WebAuthn since browsers will recognize the new value.
     */
    transports: descriptor.transports as AuthenticatorTransport[],
  };
}