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..a0dc5c2 --- /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 function decodeAuthenticatorExtensions( + extensionData: Buffer +): AuthenticationExtensionsAuthenticatorOutputs | undefined { + let toCBOR: AuthenticationExtensionsAuthenticatorOutputs | undefined; + try { + toCBOR = cbor.decodeAllSync(extensionData)[0]; + } catch (err) { + const _err = err as Error; + throw new Error(`Error decoding authenticator extensions: ${_err.message}`); + } + return toCBOR; +} + +export type AuthenticationExtensionsAuthenticatorOutputs = { + devicePublicKey?: DevicePublicKeyAuthenticatorOutput; + uvm?: UVMAuthenticatorOutput; +} + +export type DevicePublicKeyAuthenticatorOutput = { + dpk?: Buffer; + scp?: Buffer; + sig?: string; + aaguid?: Buffer; +} + +// TODO: Need to verify this format +// https://w3c.github.io/webauthn/#sctn-uvm-extension. +export type UVMAuthenticatorOutput = { + uvm?: Buffer[] +} |