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