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 | |
parent | 254b7e34d3ed028c74767dfeb0678677737df878 (diff) |
Add parseAssertionAuthData
-rw-r--r-- | src/assertion/parseAssertionAuthData.ts | 28 | ||||
-rw-r--r-- | src/types.ts | 8 |
2 files changed, 36 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, + }; +} diff --git a/src/types.ts b/src/types.ts index 59e70c1..0442b31 100644 --- a/src/types.ts +++ b/src/types.ts @@ -102,3 +102,11 @@ export type SafetyNetJWTPayload = { }; export type SafetyNetJWTSignature = string; + +export type ParsedAssertionAuthData = { + rpIdHash: Buffer, + flagsBuf: Buffer, + flags: number, + counter: number, + counterBuf: Buffer, +}; |