summaryrefslogtreecommitdiffhomepage
path: root/packages/server/src/helpers/decodeAuthenticatorExtensions.ts
blob: d4a71ea8d211cbc42dbee8cc6efe78b030e3f786 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import cbor from 'cbor';

/**
 * Convert authenticator extension data buffer to a proper object
 *
 * @param extensionData Authenticator Extension Data buffer
 */
export default function decodeAuthenticatorExtensionData(
  extensionData: Buffer
): AuthenticationExtensionsAuthenticatorOutputs | undefined {
  let toCBOR: AuthenticationExtensionsAuthenticatorOutputs | undefined;
  try {
    toCBOR = cbor.decodeAllSync(extensionData)[0];
  } catch (e) {
    console.error(e);
    toCBOR = undefined;
  }
  return toCBOR;
}

export type AuthenticationExtensionsAuthenticatorOutputs = {
  devicePublicKey?: DevicePublicKeyJSON;
  uvm?: UvmJSON;
}

export type DevicePublicKeyJSON = {
  dpk?: Buffer;
  scp?: Buffer;
  sig?: string;
  aaguid?: Buffer;
}

// TODO: Need to verify this format
// https://w3c.github.io/webauthn/#sctn-uvm-extension.
export type UvmJSON = {
  uvm?: Buffer[]
}