diff options
Diffstat (limited to 'packages/server/src/helpers/decodeAuthenticatorExtensions.ts')
-rw-r--r-- | packages/server/src/helpers/decodeAuthenticatorExtensions.ts | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/packages/server/src/helpers/decodeAuthenticatorExtensions.ts b/packages/server/src/helpers/decodeAuthenticatorExtensions.ts index b34fdc3..e6d0781 100644 --- a/packages/server/src/helpers/decodeAuthenticatorExtensions.ts +++ b/packages/server/src/helpers/decodeAuthenticatorExtensions.ts @@ -1,4 +1,4 @@ -import { decodeCborFirst } from './decodeCbor'; +import * as cbor from './cbor'; /** * Convert authenticator extension data buffer to a proper object @@ -8,14 +8,15 @@ import { decodeCborFirst } from './decodeCbor'; export function decodeAuthenticatorExtensions( extensionData: Uint8Array, ): AuthenticationExtensionsAuthenticatorOutputs | undefined { - let toCBOR: AuthenticationExtensionsAuthenticatorOutputs | undefined; + let toCBOR: Map<string, unknown>; try { - toCBOR = decodeCborFirst(extensionData); + toCBOR = cbor.decodeFirst(extensionData); } catch (err) { const _err = err as Error; throw new Error(`Error decoding authenticator extensions: ${_err.message}`); } - return toCBOR; + + return convertMapToObjectDeep(toCBOR); } export type AuthenticationExtensionsAuthenticatorOutputs = { @@ -25,8 +26,9 @@ export type AuthenticationExtensionsAuthenticatorOutputs = { export type DevicePublicKeyAuthenticatorOutput = { dpk?: Uint8Array; - scp?: Uint8Array; sig?: string; + nonce?: Uint8Array; + scope?: Uint8Array; aaguid?: Uint8Array; }; @@ -35,3 +37,22 @@ export type DevicePublicKeyAuthenticatorOutput = { export type UVMAuthenticatorOutput = { uvm?: Uint8Array[]; }; + +/** + * CBOR-encoded extensions can be deeply-nested Maps, which are too deep for a simple + * `Object.entries()`. This method will recursively make sure that all Maps are converted into + * basic objects. + */ +function convertMapToObjectDeep(input: Map<string, unknown>): { [key: string]: unknown } { + const mapped: { [key: string]: unknown } = {}; + + for (const [key, value] of input) { + if (value instanceof Map) { + mapped[key] = convertMapToObjectDeep(value); + } else { + mapped[key] = value; + } + } + + return mapped; +} |