decord/alpha/source/utils/MFAUtils.tsx

80 lines
2.4 KiB
TypeScript
Raw Permalink Normal View History

2026-10-12 06:59:38 +00:00
// Module ID: 6633
// Function ID: 6634
// Name: MFAUtils
2026-10-12 06:59:38 +00:00
// Dependencies: [1628, 6634, 1255, 2]
2026-07-29 08:29:29 +00:00
// Exports: captureWebAuthnException, encodeTotpSecret, encodeTotpSecretAsUrl, generateTotpSecret
2026-07-20 16:05:17 +00:00
2026-10-12 06:59:38 +00:00
// Module 6633 (MFAUtils)
2026-10-09 10:00:15 +00:00
import SentryUtilsDefault from "SentryUtils" /* 1255 */;
2026-10-12 06:59:38 +00:00
import encodeDefault from "encode" /* 6634 */;
2026-10-09 10:00:15 +00:00
import MetaQuestUtils from "MetaQuestUtils" /* 1628 */;
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;
2026-10-03 08:58:59 +00:00
const tmp4 = "Uint8Array" in window;
2026-07-20 16:05:17 +00:00
if (tmp5) {
2026-10-03 08:58:59 +00:00
let str = "getRandomValues";
2026-07-20 16:05:17 +00:00
tmp5 = "getRandomValues" in _crypto;
}
if (tmp5) {
tmp5 = tmp4;
}
2026-07-29 08:29:29 +00:00
function encodeTotpSecret(totpSecret) {
2026-10-03 08:58:59 +00:00
const str = totpSecret.replace(/[\s._-]+/g, "");
return str.toUpperCase();
2026-07-29 08:29:29 +00:00
}
2026-10-03 08:58:59 +00:00
const tmp6 = !MetaQuestUtils.isMetaQuest();
const result = size.fileFinishedImporting("utils/MFAUtils.tsx");
2026-07-20 16:05:17 +00:00
export const hasCrypto = tmp5;
2026-10-03 08:58:59 +00:00
export const hasWebAuthn = tmp6;
2026-07-20 16:05:17 +00:00
export const generateTotpSecret = function generateTotpSecret() {
2026-10-03 08:58:59 +00:00
const getRandomValues = _crypto.getRandomValues;
2026-07-20 16:05:17 +00:00
const uint8Array = new Uint8Array(20);
2026-10-03 08:58:59 +00:00
const randomValues = getRandomValues(uint8Array);
const encoder = encodeDefault;
const str = encoder.encode(randomValues);
2026-10-03 08:58:59 +00:00
const str2 = str.toString("utf8");
const str3 = str2.replace(/=/g, "");
const str4 = str3.toLowerCase();
const str5 = str4.replace(/(\w{4})/g, "$1 ");
return str5.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-10-03 08:58:59 +00:00
const str2 = str.replace(/[\s._-]+/g, "");
const formatted = str2.toUpperCase();
2026-07-29 08:29:29 +00:00
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) {
2026-10-03 08:58:59 +00:00
let obj2;
const obj = { tags: obj2 };
const captureException = SentryUtilsDefault.captureException;
SentryUtilsDefault;
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;
}
2026-10-03 08:58:59 +00:00
obj2 = { app_context: "webauthn" };
2026-07-20 16:05:17 +00:00
const merged1 = Object.assign(tags);
2026-10-03 08:58:59 +00:00
captureException(error, obj);
2026-07-20 16:05:17 +00:00
};