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.
37 lines
1.1 KiB
37 lines
1.1 KiB
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.decodeAuthenticatorExtensions = decodeAuthenticatorExtensions;
|
|
const index_js_1 = require("./iso/index.js");
|
|
/**
|
|
* Convert authenticator extension data buffer to a proper object
|
|
*
|
|
* @param extensionData Authenticator Extension Data buffer
|
|
*/
|
|
function decodeAuthenticatorExtensions(extensionData) {
|
|
let toCBOR;
|
|
try {
|
|
toCBOR = index_js_1.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;
|
|
}
|
|
|