diff options
author | Matthew Miller <matthew@millerti.me> | 2020-05-19 14:00:23 -0700 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2020-05-19 14:00:23 -0700 |
commit | d7784a1e4efd682aaf0ea5f44dc14df2d53f4001 (patch) | |
tree | 67b6ea8c0fcad58649abcdefc7789b753079b81a /src/assertion/parseAssertionAuthData.ts | |
parent | 254b7e34d3ed028c74767dfeb0678677737df878 (diff) |
Add parseAssertionAuthData
Diffstat (limited to 'src/assertion/parseAssertionAuthData.ts')
-rw-r--r-- | src/assertion/parseAssertionAuthData.ts | 28 |
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, + }; +} |