decord/source/utils/MFAUtils.tsx

78 lines
2.5 KiB
TypeScript
Raw Normal View History

// Module ID: 7059
// Function ID: 7060
// Name: MFAUtils
// Dependencies: [17, 1609, 7060, 1231, 2]
2026-07-29 08:29:29 +00:00
// Exports: captureWebAuthnException, encodeTotpSecret, encodeTotpSecretAsUrl, generateTotpSecret
2026-07-20 16:05:17 +00:00
// Module 7059 (MFAUtils)
import _mod17 from "module_17" /* 17 */;
import SentryUtilsDefault from "SentryUtils" /* 1231 */;
import MetaQuestUtils from "MetaQuestUtils" /* 1609 */;
import encodeDefault from "encode" /* 7060 */;
import size from "module_2" /* 2 */;
2026-08-24 06:08:38 +00:00
2026-07-20 16:05:17 +00:00
let _crypto;
2026-07-29 08:29:29 +00:00
if (window != null) {
2026-07-20 16:05:17 +00:00
_crypto = window.crypto;
}
2026-07-29 08:29:29 +00:00
if (_crypto == null) {
2026-07-20 16:05:17 +00:00
let msCrypto;
2026-07-29 08:29:29 +00:00
if (window != null) {
2026-07-20 16:05:17 +00:00
msCrypto = window.msCrypto;
}
_crypto = msCrypto;
}
let tmp5 = null != _crypto;
if (tmp5) {
tmp5 = "getRandomValues" in _crypto;
}
if (tmp5) {
tmp5 = tmp4;
}
let tmp6 = null != _mod17.NativeModules.DCDSecurityKeyManager;
2026-07-20 16:05:17 +00:00
if (tmp6) {
const _module = MetaQuestUtils;
2026-07-20 16:05:17 +00:00
tmp6 = !_module.isMetaQuest();
}
2026-07-29 08:29:29 +00:00
function encodeTotpSecret(totpSecret) {
return totpSecret.replace(/[\s._-]+/g, "").toUpperCase();
}
const result = size.fileFinishedImporting("utils/MFAUtils.tsx");
2026-07-20 16:05:17 +00:00
export const hasCrypto = tmp5;
export const hasWebAuthn = tmp6;
export const generateTotpSecret = function generateTotpSecret() {
const uint8Array = new Uint8Array(20);
const randomValues = _crypto.getRandomValues(uint8Array);
const encoder = encodeDefault;
const str = encoder.encode(randomValues);
const str2 = encoder.encode(randomValues).toString("utf8");
const str3 = encoder.encode(randomValues).toString("utf8").replace(/=/g, "");
const str4 = encoder.encode(randomValues).toString("utf8").replace(/=/g, "").toLowerCase();
return encoder.encode(randomValues).toString("utf8").replace(/=/g, "").toLowerCase().replace(/(\w{4})/g, "$1 ").trim();
2026-07-20 16:05:17 +00:00
};
export { encodeTotpSecret };
2026-07-29 08:29:29 +00:00
export const encodeTotpSecretAsUrl = function encodeTotpSecretAsUrl(arg0, str) {
str = arg2;
2026-07-20 16:05:17 +00:00
if (arg2 === undefined) {
str = "Discord";
}
const encodeURIResult = encodeURI(str);
const encodeURIResult1 = encodeURI(arg0);
2026-07-29 08:29:29 +00:00
const formatted = str.replace(/[\s._-]+/g, "").toUpperCase();
return "otpauth://totp/" + encodeURIResult + ":" + encodeURIResult1 + "?secret=" + formatted + "&issuer=" + encodeURIComponent(str);
2026-07-20 16:05:17 +00:00
};
export const captureWebAuthnException = function captureWebAuthnException(error, tags) {
const obj2 = {};
2026-07-20 16:05:17 +00:00
const merged = Object.assign(tags);
tags = undefined;
2026-07-29 08:29:29 +00:00
if (tags != null) {
2026-07-20 16:05:17 +00:00
tags = tags.tags;
}
const obj3 = {};
2026-07-20 16:05:17 +00:00
const merged1 = Object.assign(tags);
obj3.app_context = "webauthn";
obj2.tags = obj3;
SentryUtilsDefault.captureException(error, obj2);
2026-07-20 16:05:17 +00:00
};