summaryrefslogtreecommitdiffhomepage
path: root/packages/server/src/helpers/decodeAttestationObject.ts
blob: 2eb99972ad4b276e4b33babd470ba2ac6990ca06 (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
import base64url from 'base64url';
import cbor from 'cbor';

/**
 * Convert an AttestationObject from base64url string to a proper object
 *
 * @param base64AttestationObject Base64URL-encoded Attestation Object
 */
export default function decodeAttestationObject(
  base64AttestationObject: string,
): AttestationObject {
  const toBuffer = base64url.toBuffer(base64AttestationObject);
  const toCBOR: AttestationObject = cbor.decodeAllSync(toBuffer)[0];
  return toCBOR;
}

export enum ATTESTATION_FORMATS {
  FIDO_U2F = 'fido-u2f',
  PACKED = 'packed',
  ANDROID_SAFETYNET = 'android-safetynet',
  NONE = 'none',
}

export type AttestationObject = {
  fmt: ATTESTATION_FORMATS;
  attStmt: {
    sig?: Buffer;
    x5c?: Buffer[];
    response?: Buffer;
  };
  authData: Buffer;
};