diff options
Diffstat (limited to 'packages/server/src/helpers/decodeAuthenticatorExtensions.ts')
-rw-r--r-- | packages/server/src/helpers/decodeAuthenticatorExtensions.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/packages/server/src/helpers/decodeAuthenticatorExtensions.ts b/packages/server/src/helpers/decodeAuthenticatorExtensions.ts new file mode 100644 index 0000000..d4a71ea --- /dev/null +++ b/packages/server/src/helpers/decodeAuthenticatorExtensions.ts @@ -0,0 +1,37 @@ +import cbor from 'cbor'; + +/** + * Convert authenticator extension data buffer to a proper object + * + * @param extensionData Authenticator Extension Data buffer + */ +export default function decodeAuthenticatorExtensionData( + extensionData: Buffer +): AuthenticationExtensionsAuthenticatorOutputs | undefined { + let toCBOR: AuthenticationExtensionsAuthenticatorOutputs | undefined; + try { + toCBOR = cbor.decodeAllSync(extensionData)[0]; + } catch (e) { + console.error(e); + toCBOR = undefined; + } + return toCBOR; +} + +export type AuthenticationExtensionsAuthenticatorOutputs = { + devicePublicKey?: DevicePublicKeyJSON; + uvm?: UvmJSON; +} + +export type DevicePublicKeyJSON = { + dpk?: Buffer; + scp?: Buffer; + sig?: string; + aaguid?: Buffer; +} + +// TODO: Need to verify this format +// https://w3c.github.io/webauthn/#sctn-uvm-extension. +export type UvmJSON = { + uvm?: Buffer[] +} |