diff options
author | Matthew Miller <matthew@millerti.me> | 2022-11-11 15:43:25 -0800 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2022-11-11 15:43:25 -0800 |
commit | 348cb774d3a00399d29578cc6d2f6e415d626464 (patch) | |
tree | 710e5f7654b44c17d4c983fadeab4efa40a46431 /packages/server/src/helpers/decodeAuthenticatorExtensions.ts | |
parent | bdf25f4808446d5edcad229492ec1a34d18656b2 (diff) |
Refactor decodeAuthenticatorExtensions
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; +} |