summaryrefslogtreecommitdiffhomepage
path: root/packages/server/src/assertion/parseAssertionAuthData.ts
blob: e6aa01102981e5c0797ca1b50461bcad0b36bdfb (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
import { ParsedAssertionAuthData } from "@libTypes";

/**
 * Make sense of the authData buffer contained in an Assertion
 */
export default function parseAssertionAuthData(authData: Buffer): ParsedAssertionAuthData {
  let intBuffer = authData;

  const rpIdHash = intBuffer.slice(0, 32);
  intBuffer = intBuffer.slice(32);

  const flagsBuf = intBuffer.slice(0, 1);
  intBuffer = intBuffer.slice(1);

  const flags = flagsBuf[0];
  const counterBuf = intBuffer.slice(0, 4);
  intBuffer = intBuffer.slice(4);

  const counter = counterBuf.readUInt32BE(0);

  return {
    rpIdHash,
    flagsBuf,
    flags,
    counter,
    counterBuf,
  };
}