summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers/toPublicKeyCredentialDescriptor.ts
blob: 127713a90c824a78f3167ac0431788a19fa8e319 (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[],
  };
}