summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/helpers/toPublicKeyCredentialDescriptor.ts
blob: e4c34a2392834ae20590a1a8fca5e4c5a740bcd2 (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 function toPublicKeyCredentialDescriptor(
  descriptor: PublicKeyCredentialDescriptorJSON,
): PublicKeyCredentialDescriptor {
  const { id } = descriptor;

  return {
    ...descriptor,
    id: base64URLStringToBuffer(id),
    /**
     * `descriptor.transports` is an array of our `AuthenticatorTransportFuture` 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[],
  };
}