mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
core&ui: add webauthn support (#484)
Co-authored-by: panda <panda_dtdyy@outlook.com> Co-authored-by: undefined <i@undefined.moe>
This commit is contained in:
1 parent
3d3a5480e3
commit
d069fe127b
29 files changed
+621
-195
No files matched your search
@@ -17,6 +17,18 @@ export function delay(ms) {
|
||||
return new Promise((resolve) => { setTimeout(resolve, ms); });
|
||||
}
|
||||
|
||||
const defaultDict = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
|
||||
|
||||
export function secureRandomString(digit = 32, dict = defaultDict) {
|
||||
let result = '';
|
||||
const crypto = window.crypto || (window as any).msCrypto;
|
||||
if (!crypto?.getRandomValues) throw new Error('crypto.getRandomValues not supported');
|
||||
const array = new Uint32Array(digit);
|
||||
crypto.getRandomValues(array);
|
||||
for (let i = 0; i < digit; i++) result += dict[array[i] % dict.length];
|
||||
return result;
|
||||
}
|
||||
|
||||
type Substitution = string | number | { templateRaw: true, html: string };
|
||||
|
||||
export function tpl(pieces: TemplateStringsArray, ...substitutions: Substitution[]) {
|
||||
@@ -146,6 +158,7 @@ Object.assign(window.Hydro.utils, {
|
||||
i18n,
|
||||
rawHtml,
|
||||
substitute,
|
||||
secureRandomString,
|
||||
request,
|
||||
tpl,
|
||||
delay,
|
||||
|
||||
Reference in new issue
Block a user