mirror of https://github.com/ghostfolio/ghostfolio
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1006 B
34 lines
1006 B
import { isoCBOR } from './iso/index.js';
|
|
/**
|
|
* Convert authenticator extension data buffer to a proper object
|
|
*
|
|
* @param extensionData Authenticator Extension Data buffer
|
|
*/
|
|
export function decodeAuthenticatorExtensions(extensionData) {
|
|
let toCBOR;
|
|
try {
|
|
toCBOR = isoCBOR.decodeFirst(extensionData);
|
|
}
|
|
catch (err) {
|
|
const _err = err;
|
|
throw new Error(`Error decoding authenticator extensions: ${_err.message}`);
|
|
}
|
|
return convertMapToObjectDeep(toCBOR);
|
|
}
|
|
/**
|
|
* 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) {
|
|
const mapped = {};
|
|
for (const [key, value] of input) {
|
|
if (value instanceof Map) {
|
|
mapped[key] = convertMapToObjectDeep(value);
|
|
}
|
|
else {
|
|
mapped[key] = value;
|
|
}
|
|
}
|
|
return mapped;
|
|
}
|
|
|