summaryrefslogtreecommitdiffhomepage
path: root/src/assertion/parseAssertionAuthData.ts
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2020-05-19 14:00:23 -0700
committerMatthew Miller <matthew@millerti.me>2020-05-19 14:00:23 -0700
commitd7784a1e4efd682aaf0ea5f44dc14df2d53f4001 (patch)
tree67b6ea8c0fcad58649abcdefc7789b753079b81a /src/assertion/parseAssertionAuthData.ts
parent254b7e34d3ed028c74767dfeb0678677737df878 (diff)
Add parseAssertionAuthData
Diffstat (limited to 'src/assertion/parseAssertionAuthData.ts')
-rw-r--r--src/assertion/parseAssertionAuthData.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/assertion/parseAssertionAuthData.ts b/src/assertion/parseAssertionAuthData.ts
new file mode 100644
index 0000000..5b11059
--- /dev/null
+++ b/src/assertion/parseAssertionAuthData.ts
@@ -0,0 +1,28 @@
+import { ParsedAssertionAuthData } from "@types";
+
+/**
+ * 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,
+ };
+}