diff options
Diffstat (limited to 'src/helpers/parseAttestationAuthData.ts')
-rw-r--r-- | src/helpers/parseAttestationAuthData.ts | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/helpers/parseAttestationAuthData.ts b/src/helpers/parseAttestationAuthData.ts new file mode 100644 index 0000000..951c0af --- /dev/null +++ b/src/helpers/parseAttestationAuthData.ts @@ -0,0 +1,63 @@ +import { ParsedAttestationAuthData } from "@lib/types"; + +/** + * Make sense of the authData buffer contained in an Attestation + */ +export default function parseAttestationAuthData(authData: Buffer): ParsedAttestationAuthData { + console.log('parsing attestation auth data'); + + let intBuffer = authData; + + const rpIdHash = intBuffer.slice(0, 32); + intBuffer = intBuffer.slice(32); + + const flagsBuf = intBuffer.slice(0, 1); + intBuffer = intBuffer.slice(1); + + const flagsInt = flagsBuf[0]; + + const flags = { + up: !!(flagsInt & 0x01), + uv: !!(flagsInt & 0x04), + at: !!(flagsInt & 0x40), + ed: !!(flagsInt & 0x80), + flagsInt, + }; + + console.debug('flags:', flags); + + const counterBuf = intBuffer.slice(0, 4); + intBuffer = intBuffer.slice(4); + + const counter = counterBuf.readUInt32BE(0); + + let aaguid: Buffer | undefined = undefined; + let credentialID: Buffer | undefined = undefined; + let COSEPublicKey: Buffer | undefined = undefined; + + if (flags.at) { + aaguid = intBuffer.slice(0, 16); + intBuffer = intBuffer.slice(16); + + const credIDLenBuf = intBuffer.slice(0, 2); + intBuffer = intBuffer.slice(2); + + const credIDLen = credIDLenBuf.readUInt16BE(0); + + credentialID = intBuffer.slice(0, credIDLen); + intBuffer = intBuffer.slice(credIDLen); + + COSEPublicKey = intBuffer; + } + + return { + rpIdHash, + flagsBuf, + flags, + counter, + counterBuf, + aaguid, + credentialID, + COSEPublicKey, + }; +} |